From nobody Sun May 5 02:26:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1615373119; cv=none; d=zohomail.com; s=zohoarc; b=hYbf1MUJuwZQf2KA7fzXYd+085jxkGag1PB0Vf62mPFG0jkTbDqnKCjxsvmqtBMX7dnwf8uUqeJRghuZEzMiUY1D9xDvF7bjUzBvEn/BXmBg9fkTpnX6nOCZHthW87znIpg8Bk2eGj+lRXHWGq1ga09ALsoBY9F1jmh6dBX8O9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615373119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=auDrX8MZ83gAoUw+7BpRkycrdv7LFLuKqOyiZSwy028=; b=D8nM1eCLfTMMM4ZMhRKmeMdYoFFPkk4+eRgAa5d/iY4Ozie0CSOhVepGamdhd1ZvnG6aJfRlMgZ7zTSLRM1TU+Zu/J0mLC2ZfUMY6r71nd63Zxv193QjNZADsrR0hkoynT0gyWGVgO4h2avnBpRmOkeeT9SHSWKs8YubQ18sADc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615373119861413.7635946211493; Wed, 10 Mar 2021 02:45:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95982.181303 (Exim 4.92) (envelope-from ) id 1lJwKt-0003gG-Kx; Wed, 10 Mar 2021 10:45:03 +0000 Received: by outflank-mailman (output) from mailman id 95982.181303; Wed, 10 Mar 2021 10:45:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwKt-0003g9-Ht; Wed, 10 Mar 2021 10:45:03 +0000 Received: by outflank-mailman (input) for mailman id 95982; Wed, 10 Mar 2021 10:45:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwKs-0003g1-Qu for xen-devel@lists.xenproject.org; Wed, 10 Mar 2021 10:45:02 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 07f34e48-b43f-4b95-9233-6c324fcba987; Wed, 10 Mar 2021 10:45:01 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BEE2DAC24; Wed, 10 Mar 2021 10:45:00 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 07f34e48-b43f-4b95-9233-6c324fcba987 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615373100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=auDrX8MZ83gAoUw+7BpRkycrdv7LFLuKqOyiZSwy028=; b=U6KSOMYSnqdrAhjabRmOrA8sANDOgTUDp0Tcij6mADEbEb8k2sN2Xes4fS4yeXaQhPMTX1 48jmJGbBAuGb/qRlX86u20JXvII8RsZQlZMKCNChd0N6rZp2J4LPc8yG/QuzLFLt2WFgLM zq9/iT1sue4pokc+jwjl+LbrAMwyICE= Subject: [PATCH 1/3] Xen/gntdev: don't needlessly allocate k{,un}map_ops[] From: Jan Beulich To: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Cc: "xen-devel@lists.xenproject.org" References: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Message-ID: <180d50cb-5531-8952-4bf0-d65c554638ed@suse.com> Date: Wed, 10 Mar 2021 11:45:00 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" They're needed only in the not-auto-translate (i.e. PV) case; there's no point in allocating memory that's never going to get accessed. Signed-off-by: Jan Beulich Reviewed-by: Juergen Gross --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -136,17 +136,20 @@ struct gntdev_grant_map *gntdev_alloc_ma add->grants =3D kvcalloc(count, sizeof(add->grants[0]), GFP_KERNEL); add->map_ops =3D kvcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL); add->unmap_ops =3D kvcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL); - add->kmap_ops =3D kvcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL); - add->kunmap_ops =3D kvcalloc(count, - sizeof(add->kunmap_ops[0]), GFP_KERNEL); add->pages =3D kvcalloc(count, sizeof(add->pages[0]), GFP_KERNEL); if (NULL =3D=3D add->grants || NULL =3D=3D add->map_ops || NULL =3D=3D add->unmap_ops || - NULL =3D=3D add->kmap_ops || - NULL =3D=3D add->kunmap_ops || NULL =3D=3D add->pages) goto err; + if (use_ptemod) { + add->kmap_ops =3D kvcalloc(count, sizeof(add->kmap_ops[0]), + GFP_KERNEL); + add->kunmap_ops =3D kvcalloc(count, sizeof(add->kunmap_ops[0]), + GFP_KERNEL); + if (NULL =3D=3D add->kmap_ops || NULL =3D=3D add->kunmap_ops) + goto err; + } =20 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC add->dma_flags =3D dma_flags; @@ -185,8 +188,10 @@ struct gntdev_grant_map *gntdev_alloc_ma for (i =3D 0; i < count; i++) { add->map_ops[i].handle =3D -1; add->unmap_ops[i].handle =3D -1; - add->kmap_ops[i].handle =3D -1; - add->kunmap_ops[i].handle =3D -1; + if (use_ptemod) { + add->kmap_ops[i].handle =3D -1; + add->kunmap_ops[i].handle =3D -1; + } } =20 add->index =3D 0; @@ -332,8 +337,8 @@ int gntdev_map_grant_pages(struct gntdev } =20 pr_debug("map %d+%d\n", map->index, map->count); - err =3D gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL, - map->pages, map->count); + err =3D gnttab_map_refs(map->map_ops, map->kmap_ops, map->pages, + map->count); =20 for (i =3D 0; i < map->count; i++) { if (map->map_ops[i].status =3D=3D GNTST_okay) From nobody Sun May 5 02:26:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1615373152; cv=none; d=zohomail.com; s=zohoarc; b=cYqcTK3dYeuFl8Mkvjqf4/LD4aHT5LNT1yUKiBgcvF/SYHMdf4Y5nQuxmz+5y/KeA+X6X+yaBmVg+0tRwtpGiv+VmwZM5y6Ny71zBZOxJImmWl4NsuzoxvVN++UL3QxQaNnaptJyVuLQhcpP/Lq9HYTs15mNgfNqYH/kHU0TTnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615373152; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ril/4RPeyhImho9ia6AHwhyvGLcmYtjyWfmoZsXmzHI=; b=aIv2yKHJJfO0FzjXIjikrBsFFe5ZvvHrvG+F+gwe6P4WKWajcWudWuGX4y3abE5uiLIqkzFn4shtcDmo5CCu54uasFXfrndgGrs9YF8pzbJA1KcOXJLNvh6fa4wIAhPfndCd/i3ImMDoa66T5jFCVGIxjyXjYs/WVuNiPxkKUSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615373152808920.0914812625326; Wed, 10 Mar 2021 02:45:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95984.181315 (Exim 4.92) (envelope-from ) id 1lJwLJ-0003nn-Vd; Wed, 10 Mar 2021 10:45:29 +0000 Received: by outflank-mailman (output) from mailman id 95984.181315; Wed, 10 Mar 2021 10:45:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwLJ-0003ng-R4; Wed, 10 Mar 2021 10:45:29 +0000 Received: by outflank-mailman (input) for mailman id 95984; Wed, 10 Mar 2021 10:45:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwLI-0003nO-A8 for xen-devel@lists.xenproject.org; Wed, 10 Mar 2021 10:45:28 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f13af8c0-4ab6-4ec7-b818-c98ca372a428; Wed, 10 Mar 2021 10:45:27 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 775B5AE7B; Wed, 10 Mar 2021 10:45:26 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f13af8c0-4ab6-4ec7-b818-c98ca372a428 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615373126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ril/4RPeyhImho9ia6AHwhyvGLcmYtjyWfmoZsXmzHI=; b=kCtLZPpVoqLhEwxjvs2rkNk3Vi8Dcw8h4kl3Q53Zz/olDnQvXyadOtBa1UcYJ+UR2wRg6s MDfx2tUyyPFIH4tDYXbp21bAlkf997nM7CnnudqZJOODWgbBWFJ3HmVv/puxnAokAC2hu0 CDBjJ/doFJMCpVAi8LCiIUODcl8FYsY= Subject: [PATCH 2/3] Xen/gnttab: introduce common INVALID_GRANT_{HANDLE,REF} From: Jan Beulich To: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Cc: "xen-devel@lists.xenproject.org" References: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Message-ID: Date: Wed, 10 Mar 2021 11:45:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" It's not helpful if every driver has to cook its own. Generalize xenbus'es INVALID_GRANT_HANDLE and pcifront's INVALID_GRANT_REF (which shouldn't have expanded to zero to begin with). Use the constants in p2m.c and gntdev.c right away, and update field types where necessary so they would match with the constants' types (albeit without touching struct ioctl_gntdev_grant_ref's ref field, as that's part of the public interface of the kernel and would require introducing a dependency on Xen's grant_table.h public header). Signed-off-by: Jan Beulich Reviewed-by: Juergen Gross --- a/arch/arm/xen/p2m.c +++ b/arch/arm/xen/p2m.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include =20 @@ -109,7 +110,7 @@ int set_foreign_p2m_mapping(struct gntta map_ops[i].status =3D GNTST_general_error; unmap.host_addr =3D map_ops[i].host_addr, unmap.handle =3D map_ops[i].handle; - map_ops[i].handle =3D ~0; + map_ops[i].handle =3D INVALID_GRANT_HANDLE; if (map_ops[i].flags & GNTMAP_device_map) unmap.dev_bus_addr =3D map_ops[i].dev_bus_addr; else --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -741,7 +741,7 @@ int set_foreign_p2m_mapping(struct gntta map_ops[i].status =3D GNTST_general_error; unmap[0].host_addr =3D map_ops[i].host_addr, unmap[0].handle =3D map_ops[i].handle; - map_ops[i].handle =3D ~0; + map_ops[i].handle =3D INVALID_GRANT_HANDLE; if (map_ops[i].flags & GNTMAP_device_map) unmap[0].dev_bus_addr =3D map_ops[i].dev_bus_addr; else @@ -751,7 +751,7 @@ int set_foreign_p2m_mapping(struct gntta kmap_ops[i].status =3D GNTST_general_error; unmap[1].host_addr =3D kmap_ops[i].host_addr, unmap[1].handle =3D kmap_ops[i].handle; - kmap_ops[i].handle =3D ~0; + kmap_ops[i].handle =3D INVALID_GRANT_HANDLE; if (kmap_ops[i].flags & GNTMAP_device_map) unmap[1].dev_bus_addr =3D kmap_ops[i].dev_bus_addr; else --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -26,7 +26,7 @@ #include =20 #include -#define INVALID_GRANT_REF (0) + #define INVALID_EVTCHN (-1) =20 struct pci_bus_entry { @@ -42,7 +42,7 @@ struct pcifront_device { struct list_head root_buses; =20 int evtchn; - int gnt_ref; + grant_ref_t gnt_ref; =20 int irq; =20 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -186,11 +186,11 @@ struct gntdev_grant_map *gntdev_alloc_ma goto err; =20 for (i =3D 0; i < count; i++) { - add->map_ops[i].handle =3D -1; - add->unmap_ops[i].handle =3D -1; + add->map_ops[i].handle =3D INVALID_GRANT_HANDLE; + add->unmap_ops[i].handle =3D INVALID_GRANT_HANDLE; if (use_ptemod) { - add->kmap_ops[i].handle =3D -1; - add->kunmap_ops[i].handle =3D -1; + add->kmap_ops[i].handle =3D INVALID_GRANT_HANDLE; + add->kunmap_ops[i].handle =3D INVALID_GRANT_HANDLE; } } =20 @@ -279,7 +279,7 @@ static int find_grant_ptes(pte_t *pte, u map->grants[pgnr].ref, map->grants[pgnr].domid); gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, - -1 /* handle */); + INVALID_GRANT_HANDLE); return 0; } =20 @@ -297,7 +297,7 @@ int gntdev_map_grant_pages(struct gntdev =20 if (!use_ptemod) { /* Note: it could already be mapped */ - if (map->map_ops[0].handle !=3D -1) + if (map->map_ops[0].handle !=3D INVALID_GRANT_HANDLE) return 0; for (i =3D 0; i < map->count; i++) { unsigned long addr =3D (unsigned long) @@ -306,7 +306,7 @@ int gntdev_map_grant_pages(struct gntdev map->grants[i].ref, map->grants[i].domid); gnttab_set_unmap_op(&map->unmap_ops[i], addr, - map->flags, -1 /* handle */); + map->flags, INVALID_GRANT_HANDLE); } } else { /* @@ -332,7 +332,7 @@ int gntdev_map_grant_pages(struct gntdev map->grants[i].ref, map->grants[i].domid); gnttab_set_unmap_op(&map->kunmap_ops[i], address, - flags, -1); + flags, INVALID_GRANT_HANDLE); } } =20 @@ -390,7 +390,7 @@ static int __unmap_grant_pages(struct gn pr_debug("unmap handle=3D%d st=3D%d\n", map->unmap_ops[offset+i].handle, map->unmap_ops[offset+i].status); - map->unmap_ops[offset+i].handle =3D -1; + map->unmap_ops[offset+i].handle =3D INVALID_GRANT_HANDLE; } return err; } @@ -406,13 +406,15 @@ static int unmap_grant_pages(struct gntd * already unmapped some of the grants. Only unmap valid ranges. */ while (pages && !err) { - while (pages && map->unmap_ops[offset].handle =3D=3D -1) { + while (pages && + map->unmap_ops[offset].handle =3D=3D INVALID_GRANT_HANDLE) { offset++; pages--; } range =3D 0; while (range < pages) { - if (map->unmap_ops[offset+range].handle =3D=3D -1) + if (map->unmap_ops[offset + range].handle =3D=3D + INVALID_GRANT_HANDLE) break; range++; } --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h @@ -50,6 +50,13 @@ #include #include =20 +/* + * Technically there's no reliably invalid grant reference or grant handle, + * so pick the value that is the most unlikely one to be observed valid. + */ +#define INVALID_GRANT_REF ((grant_ref_t)-1) +#define INVALID_GRANT_HANDLE ((grant_handle_t)-1) + #define GNTTAB_RESERVED_XENSTORE 1 =20 /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -51,7 +51,6 @@ =20 #define XENBUS_MAX_RING_GRANT_ORDER 4 #define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER) -#define INVALID_GRANT_HANDLE (~0U) =20 /* Register callback to watch this node. */ struct xenbus_watch From nobody Sun May 5 02:26:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1615373197; cv=none; d=zohomail.com; s=zohoarc; b=VWfb9eE3yNZPEVVaCZ1ud/RuSr7z0Jsl5RYaee8647Zg3ZaLQFp3SglP4zrY34mjXEticwzqhYkEbnH0PJfFeI53ghvoObJbUV8A33eOX8R4cH7ULLgU/mBMwQ3eFR0wQdskEBMOVQI1F3Zyz9qCmNH12pSsyxVbMe8k9smqybY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615373197; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yvUHprKx53TaVD+UfRnNYW7HFBxwI5hyLFfjImK+NmI=; b=lVZxmIIrgFFi0Rb3QzuJeqAgdfpGt3H7JaehcRMPkW3v4F13NJ4QOw08nMhcFJiFV7u+y4gxsBtn4iIL6QGiu4ZnIRGANtytPkIbtAD1af0oYeU8jQGmUBG078wa7fT/8ZIs1qVVPNVbzJxHUZ1AgMllwnBJGXsohSdsvLSxta8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161537319791521.465256083594795; Wed, 10 Mar 2021 02:46:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95989.181329 (Exim 4.92) (envelope-from ) id 1lJwM4-0003ws-A3; Wed, 10 Mar 2021 10:46:16 +0000 Received: by outflank-mailman (output) from mailman id 95989.181329; Wed, 10 Mar 2021 10:46:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwM4-0003wl-7A; Wed, 10 Mar 2021 10:46:16 +0000 Received: by outflank-mailman (input) for mailman id 95989; Wed, 10 Mar 2021 10:46:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJwM2-0003wc-Dt for xen-devel@lists.xenproject.org; Wed, 10 Mar 2021 10:46:14 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 74e6b74e-0ced-4df2-982c-200d980c9508; Wed, 10 Mar 2021 10:46:13 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 017F9AC24; Wed, 10 Mar 2021 10:46:13 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 74e6b74e-0ced-4df2-982c-200d980c9508 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615373173; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yvUHprKx53TaVD+UfRnNYW7HFBxwI5hyLFfjImK+NmI=; b=a08Avz/NSZFWEZLSEKggtjR0QaOpO0YEpvzKqyclVcRIFKKhJbYKiTYvp9GBR9sKc42uD9 7kH517gdlU6BcVbC0XhfYHMVO3pKWDGRVamM3iP6bt4YNG+m07xcUlKLf9x8yUJ5ytwsNC 29dfs0qEwcXQfvpA3NXgXe5G6i84mDU= Subject: [PATCH 3/3] Xen/gntdev: don't needlessly use kvcalloc() From: Jan Beulich To: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Cc: "xen-devel@lists.xenproject.org" References: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Message-ID: <9a726be2-4893-8ffe-0ef1-b70dd1c229b1@suse.com> Date: Wed, 10 Mar 2021 11:46:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <2b326dc6-c624-c97b-f9c4-4cc68dd013ba@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Requesting zeroed memory when all of it will be overwritten subsequently by all ones is a waste of processing bandwidth. In fact, rather than recording zeroed ->grants[], fill that array too with more appropriate "invalid" indicators. Signed-off-by: Jan Beulich Reviewed-by: Juergen Gross --- v2: Use (now generalized) INVALID_GRANT_REF. --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -133,9 +133,12 @@ struct gntdev_grant_map *gntdev_alloc_ma if (NULL =3D=3D add) return NULL; =20 - add->grants =3D kvcalloc(count, sizeof(add->grants[0]), GFP_KERNEL); - add->map_ops =3D kvcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL); - add->unmap_ops =3D kvcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL); + add->grants =3D kvmalloc_array(count, sizeof(add->grants[0]), + GFP_KERNEL); + add->map_ops =3D kvmalloc_array(count, sizeof(add->map_ops[0]), + GFP_KERNEL); + add->unmap_ops =3D kvmalloc_array(count, sizeof(add->unmap_ops[0]), + GFP_KERNEL); add->pages =3D kvcalloc(count, sizeof(add->pages[0]), GFP_KERNEL); if (NULL =3D=3D add->grants || NULL =3D=3D add->map_ops || @@ -143,10 +146,10 @@ struct gntdev_grant_map *gntdev_alloc_ma NULL =3D=3D add->pages) goto err; if (use_ptemod) { - add->kmap_ops =3D kvcalloc(count, sizeof(add->kmap_ops[0]), - GFP_KERNEL); - add->kunmap_ops =3D kvcalloc(count, sizeof(add->kunmap_ops[0]), - GFP_KERNEL); + add->kmap_ops =3D kvmalloc_array(count, sizeof(add->kmap_ops[0]), + GFP_KERNEL); + add->kunmap_ops =3D kvmalloc_array(count, sizeof(add->kunmap_ops[0]), + GFP_KERNEL); if (NULL =3D=3D add->kmap_ops || NULL =3D=3D add->kunmap_ops) goto err; } @@ -186,6 +189,8 @@ struct gntdev_grant_map *gntdev_alloc_ma goto err; =20 for (i =3D 0; i < count; i++) { + add->grants[i].domid =3D DOMID_INVALID; + add->grants[i].ref =3D INVALID_GRANT_REF; add->map_ops[i].handle =3D INVALID_GRANT_HANDLE; add->unmap_ops[i].handle =3D INVALID_GRANT_HANDLE; if (use_ptemod) {