From nobody Sun Apr 28 06:52:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15493191534781020.0608402575854; Mon, 4 Feb 2019 14:25:53 -0800 (PST) Received: from localhost ([127.0.0.1]:50230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqmgV-00086j-D1 for importer@patchew.org; Mon, 04 Feb 2019 17:25:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqmef-0006oj-4Y for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqmed-0001gr-4o for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:53 -0500 Received: from mail-eopbgr750044.outbound.protection.outlook.com ([40.107.75.44]:33504 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqmec-0001ZM-UD for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:51 -0500 Received: from SN6PR12MB2688.namprd12.prod.outlook.com (52.135.103.29) by SN6PR12MB2623.namprd12.prod.outlook.com (52.135.103.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1580.17; Mon, 4 Feb 2019 22:23:40 +0000 Received: from SN6PR12MB2688.namprd12.prod.outlook.com ([fe80::2cbf:7ce2:83f5:851c]) by SN6PR12MB2688.namprd12.prod.outlook.com ([fe80::2cbf:7ce2:83f5:851c%5]) with mapi id 15.20.1580.019; Mon, 4 Feb 2019 22:23:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1M+3SQDX9M2n+uXTyW/5HhpW4txD/CFH7D/8h8Ag/xQ=; b=nsLXjJ8tx+ga31r56Abjia61wReN5wfbi2w7gUMXrDo4xj1spi4QcuSSAvFSv9BMYojNfXFzTAhit//YeOtjSENHMfnhE1WZVeiEFNv7ksX9S9oQOpzxPyVkJeyMi4Oe1na9C2xYHGpat0laCzyXO9eUA1LL0h3vqqiW/UsnbQY= From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2 1/2] memory: Fix the memory region type assignment order Thread-Index: AQHUvNhHzgK+5gHxkUyEmaPbaqN0WQ== Date: Mon, 4 Feb 2019 22:23:39 +0000 Message-ID: <20190204222322.26766-2-brijesh.singh@amd.com> References: <20190204222322.26766-1-brijesh.singh@amd.com> In-Reply-To: <20190204222322.26766-1-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN6PR08CA0012.namprd08.prod.outlook.com (2603:10b6:805:66::25) To SN6PR12MB2688.namprd12.prod.outlook.com (2603:10b6:805:6f::29) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR12MB2623; 20:UNgIUG8p7AbRdpTlS8XgqsW2YhjhGVXDJEDuc5L8DQkHIqRIycukNKHNpYwAR0HIzo+LSCFNvFfF4ztPVbIZZi48mFjKly1orInTy/S6Kxc3H6m7rmPxs39QkY7jodNO+EQ6U/CRFTxV+OpJqhfG7jM/v45VD4EqOpLZB0ehPzG5n28CrQd8el9zDhVJmcrJhD9b+KNQII6ENnOve57g7JVfHWTt0US8pV+iyr/OBqniootDuWrdExNkD/dEttLN x-ms-office365-filtering-correlation-id: 4c2ca90a-5093-4968-502b-08d68aef69b7 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020); SRVR:SN6PR12MB2623; x-ms-traffictypediagnostic: SN6PR12MB2623: x-microsoft-antispam-prvs: x-forefront-prvs: 0938781D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(366004)(136003)(39860400002)(189003)(199004)(36756003)(66066001)(6506007)(106356001)(966005)(99286004)(7736002)(386003)(14454004)(478600001)(1076003)(86362001)(8936002)(81156014)(71190400001)(71200400001)(68736007)(6486002)(8676002)(81166006)(6512007)(6306002)(50226002)(305945005)(53936002)(6436002)(5640700003)(54906003)(11346002)(2616005)(6916009)(486006)(2351001)(476003)(256004)(14444005)(52116002)(2906002)(102836004)(2501003)(26005)(3846002)(6116002)(76176011)(316002)(446003)(4326008)(97736004)(105586002)(25786009)(186003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2623; H:SN6PR12MB2688.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: AcQw8xpxPbLw0bH4onu7NBDcUGWxPRQ34A6YcOWA8eQhtvzTZwJ3gcI5zb99VSSFBqgOCHMaj2jenrcySyd7gS+Tz5dOuKH+J2i1njAxQXq+XS2OrZmd602jcxmi81KaveeGHFNsEM/XVv9JfH9FyfMSnqTKueFrNByOmzQyh+LfNy1xB7qiTxjvQUgfAwZy61J3iqGEXVWQihjtiBVr3xuYc9r4SD7EREApth6gZOnDIDt4Hh4cjZfUZplE9hpZTkFKMCaom7OQSiAnoiPh35YOkZaL5INXvXWTR46qnVUP6BjOONe4rkvzDHtGiqo8sH2n3y9rfIa8DmM9veTUOptZPwCOn36HPzOut1VCYLw+mSeIPozuO2ymXnYbn1+P4Ri5/ysDPN8iCA2CL0NGqqIA8HJX/tOjF1fR7UvF77k= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c2ca90a-5093-4968-502b-08d68aef69b7 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Feb 2019 22:23:39.3460 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2623 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.75.44 Subject: [Qemu-devel] [PATCH v2 1/2] memory: Fix the memory region type assignment order X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "alex.williamson@redhat.com" , "Singh, Brijesh" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently, a callback registered through the RAMBlock notifier is not able to get the memory region type (i.e callback is not able to use memory_region_is_ram_device function). This is because mr->ram assignment happens _after_ the memory is allocated whereas the callback is executed during allocation. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1667249 Suggested-by: Alex Williamson Cc: Paolo Bonzini Reviewed-by: Alex Williamson Signed-off-by: Brijesh Singh --- memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 61d66e4441..9ec15349dd 100644 --- a/memory.c +++ b/memory.c @@ -1652,10 +1652,17 @@ void memory_region_init_ram_device_ptr(MemoryRegion= *mr, uint64_t size, void *ptr) { - memory_region_init_ram_ptr(mr, owner, name, size, ptr); + memory_region_init(mr, owner, name, size); + mr->ram =3D true; + mr->terminates =3D true; mr->ram_device =3D true; mr->ops =3D &ram_device_mem_ops; mr->opaque =3D mr; + mr->destructor =3D memory_region_destructor_ram; + mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; + /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ + assert(ptr !=3D NULL); + mr->ram_block =3D qemu_ram_alloc_from_ptr(size, ptr, mr, &error_fatal); } =20 void memory_region_init_alias(MemoryRegion *mr, --=20 2.17.1 From nobody Sun Apr 28 06:52:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549319149673816.8696182051716; Mon, 4 Feb 2019 14:25:49 -0800 (PST) Received: from localhost ([127.0.0.1]:50228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqmgS-00086X-4C for importer@patchew.org; Mon, 04 Feb 2019 17:25:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqmef-0006ok-Vc for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqmed-0001hb-KP for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:53 -0500 Received: from mail-eopbgr750044.outbound.protection.outlook.com ([40.107.75.44]:33504 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqmed-0001ZM-B4 for qemu-devel@nongnu.org; Mon, 04 Feb 2019 17:23:51 -0500 Received: from SN6PR12MB2688.namprd12.prod.outlook.com (52.135.103.29) by SN6PR12MB2623.namprd12.prod.outlook.com (52.135.103.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1580.17; Mon, 4 Feb 2019 22:23:40 +0000 Received: from SN6PR12MB2688.namprd12.prod.outlook.com ([fe80::2cbf:7ce2:83f5:851c]) by SN6PR12MB2688.namprd12.prod.outlook.com ([fe80::2cbf:7ce2:83f5:851c%5]) with mapi id 15.20.1580.019; Mon, 4 Feb 2019 22:23:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iIVLMLV1hXhuydVkpw6/866ucyQ6/6cszhpvjKUQ1m4=; b=KjfaXC40ZK9ds7MX1ggnzfPuM9kQSicZWWQ+k1nMpDXNlSY3KpNhPsXv9L1Zkc+FYcXHx2UDHCGJqdY7Kr6+DJ4lvuxjDritHH7UEUhL7tYJg+ltaumoq3JB1QtuCvixT7e5yLZ1qOq8bsZMXeZ8VDYelMr6e0XJVnvrJije+EQ= From: "Singh, Brijesh" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region Thread-Index: AQHUvNhHhDXH63KOq02xi4Pp4gU8Lw== Date: Mon, 4 Feb 2019 22:23:40 +0000 Message-ID: <20190204222322.26766-3-brijesh.singh@amd.com> References: <20190204222322.26766-1-brijesh.singh@amd.com> In-Reply-To: <20190204222322.26766-1-brijesh.singh@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN6PR08CA0012.namprd08.prod.outlook.com (2603:10b6:805:66::25) To SN6PR12MB2688.namprd12.prod.outlook.com (2603:10b6:805:6f::29) authentication-results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR12MB2623; 20:VRarYcuzGKHfhksK5nygR7qtBHoKZOhqy3cm93U7RFfj90Y1gX3NiBilIlsO62rkHzRYGpDzZKS5q7asAqfWG1Ybr0zU/PwFGgAkz2xjMdOBcfuer3XQGK/4uaMMwxK1bIa1NJux9O6mgmoghCIcJJLpgt/PSW3Kx5zPA1p99VB8SD8jpN4IWjr3J11pw2nubH/iDH+BSu/uWwBzDEEx83jhoBQesO0w3UbCf6zzqjVLBKz/dN1MX3hozSGLTBpW x-ms-office365-filtering-correlation-id: 2fd79d17-d337-4840-0462-08d68aef6a12 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020); SRVR:SN6PR12MB2623; x-ms-traffictypediagnostic: SN6PR12MB2623: x-microsoft-antispam-prvs: x-forefront-prvs: 0938781D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(366004)(136003)(39860400002)(189003)(199004)(36756003)(66066001)(6506007)(106356001)(966005)(99286004)(7736002)(386003)(14454004)(478600001)(1076003)(86362001)(8936002)(81156014)(71190400001)(71200400001)(68736007)(6486002)(8676002)(81166006)(6512007)(6306002)(50226002)(305945005)(53936002)(6436002)(5640700003)(54906003)(11346002)(2616005)(6916009)(486006)(2351001)(476003)(256004)(14444005)(52116002)(2906002)(102836004)(2501003)(26005)(3846002)(6116002)(76176011)(316002)(446003)(4326008)(97736004)(105586002)(25786009)(186003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2623; H:SN6PR12MB2688.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: jqP3HYRBvYbV0rCxnXbZ4fZAjJITrZU3co7wUEGdblql2lqEZMe8Ja2tDotaYz3RnSGrGgrekBdPtFCbhVm3qWMUXS54eZoYLnm3NklPgl2DKmL7oC7TiZrz1w2wpn8Vi+o0zjmmEW+Sf+ytzxoXNi8QhXkHOqvJOyiqnbFoN6pu2FTdk+4KgKN5GMO1w/YQZzYEXU8F2nZrxsT8fBiCkLMYkk/veRhmqK44tNcw2gKjqhjfa1VEHjDH4hGRR00s88AtyQKqpzFCU25TdNLTj8HGwqJQa9aHdR2s7xEEYQ9W54ikFijOjphd/qQF1yiy2CNIQgHgphnRYrcAaGj1LG0ioVZQmcl15hM7x8TwVpfAP5rij+//CSTeKoE904Au5CGy9W3z+ZXAIyLAo/znY0aPI36nAdIblfu5P9xXp7Q= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fd79d17-d337-4840-0462-08d68aef6a12 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Feb 2019 22:23:39.9025 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2623 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.75.44 Subject: [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "alex.williamson@redhat.com" , "Singh, Brijesh" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The RAM device presents a memory region that should be handled as an IO region and should not be pinned. In the case of the vfio-pci, RAM device represents a MMIO BAR and the memory region is not backed by pages hence KVM_MEMORY_ENCRYPT_REG_REGION fails to lock the memory range. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1667249 Cc: Alex Williamson Cc: Paolo Bonzini Signed-off-by: Brijesh Singh Reviewed-by: Alex Williamson --- target/i386/sev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 20b2d325d8..cd77f6b5d4 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -131,6 +131,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, s= ize_t size) { int r; struct kvm_enc_region range; + ram_addr_t offset; + MemoryRegion *mr; + + /* + * The RAM device presents a memory region that should be treated + * as IO region and should not be pinned. + */ + mr =3D memory_region_from_host(host, &offset); + if (mr && memory_region_is_ram_device(mr)) { + return; + } =20 range.addr =3D (__u64)(unsigned long)host; range.size =3D size; --=20 2.17.1