Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp447192rdb; Thu, 5 Oct 2023 10:21:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXsRuLLIiRFkwYOXjmS3WY8FWuz0juhae5cmC6MQ3l994dBpjOX38qAJfq9KVbf40RReoc X-Received: by 2002:a05:6808:1a27:b0:3ad:c476:9ad9 with SMTP id bk39-20020a0568081a2700b003adc4769ad9mr7760872oib.4.1696526491458; Thu, 05 Oct 2023 10:21:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696526491; cv=pass; d=google.com; s=arc-20160816; b=z3b+clkkczSSNAdvQIycpuk+vuSdPWpKoRNheLDl9TFZxlAnKRzNl3F3biRFKub8Zs sv9qY/hp8Po5h4Pdk5RqixpW5jhYNgvFRMmxswqnlIOb07YR7tmmchCv6MFVmoMG9rw6 faydhYEbPdRsuwLlGg71ttTE9BXXpXzBTDl7e+4iVfMPb/yAC7smmAEhWSnAz5mReXSm WqBBmO5hmyyx8IGWr5Q2UPwcVv8q7+Ga6tRi0v9+hpOGGjSQKJpBb3wVY6iQSqSn0h6G CidcqzKKoiwe2YdKyaWiTdHeP8JcjKUElhLgRHm6LeRux00kotlLBfKfHohGjb9rFE4t KNEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yJjRfPFE1u59tUllCuAU5kVEjftyeGOfDutmuE8RjRg=; fh=8wk8lqEkM4zMNBA3klGd2o6ugh/N14d5WOE9geYUU7M=; b=zz5NVWeegF+O5fLPYqb7Mm5sPIhBmvJS7UfmoUn5S0uf1TUbULLPK0StkrywZtE6Od qIlaoT4RD8ikGa/BQs+JG/+AK2FiZNRpr625qjpPZldL+wbTOYv3mH3skaKQ6un3twx7 t7Yy/+7FqWjQonfJxV9lj41Y9nSz9euv3rGmavZs7tb/jzO/LYRlRgYh4CwOccXRGcO4 WPdIOeifHiCGY2thDqbC9h3RAgjrULx1Nzc2Y2J5wefuAIYbwsar8sfWPzmFihJPzNUT /xqDWGoPYLulRKASdgIZxnQFULzeHWi9SFGABawCAQ+kkMAIpjKVLHcLWSZbTq6xBTny QdAQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=h9DV1JHl; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id z11-20020a6552cb000000b0056da0ae25d1si1787766pgp.831.2023.10.05.10.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 10:21:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=h9DV1JHl; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4089D80BEF24; Fri, 29 Sep 2023 11:21:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233929AbjI2SUz (ORCPT + 99 others); Fri, 29 Sep 2023 14:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233900AbjI2SUp (ORCPT ); Fri, 29 Sep 2023 14:20:45 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-centralusazon11020024.outbound.protection.outlook.com [52.101.61.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A88F0CCB; Fri, 29 Sep 2023 11:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dktBECflJjI0n1It5HpQTRIxR8cRKevUr0b1GQNjVBUx7dVihE24Vhn1nO3fE14ZWLYesYs+tUmydkQgl4ZPdyzqPxIOh3h4Xjv52r6eYtbqi4R74K5dBj32Y72EwhujWzZpLw4jus40hWdZwWCav1VEX8eIW7tZC202XBE0iWKRkZXkWor1zM44AFfspBUJYHagREXYhmZyiU7HhI/MiLcTT4NVhcLeS21ZfMh5CHZAfkrVtjDoCbf9D+mfv2rXIONV33/XWHWpnuUViJZVclSyyXLHv3XTrik7Qgtv7wcpBsMIOjgfxY8M/Ljwx9Ko4hrw/2occD8Zo+rTzug/vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yJjRfPFE1u59tUllCuAU5kVEjftyeGOfDutmuE8RjRg=; b=DcjK9mCr1mXtMcmUiz/wDj8xDdLB9WF7SU9nHJ0ydphq+0EPsg5ElmliiEwj5TBoOkcj5Wzb4qxcvi+WLNlaGuHn3hkVKBbzMqnKhdRj+u8EuontcBZi35P/Ml8WIFbsPGPdsXb6hsIPJJ+k6j+23lTAdsjuGUHBUQiZQSfGQhEM+xObw0fYtS2lJquFpKe1YdJZh/JsYjoovYJ2iRKO3NytxHWAX6gMi6AVLC1NbSfeJYl3YBzeoOMKEACne8dBmPCfBe2X5PKiqvUwTHlicuZRoDqryWU20Fx3/iu+Ny1vWZXeyzT7h+5WbaAwqpr6+cGEGMuhlWMUFJagmNxGsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yJjRfPFE1u59tUllCuAU5kVEjftyeGOfDutmuE8RjRg=; b=h9DV1JHl33wwz6I/5XBsMU/sTFM3AvQrYHjJsX2nFPB9HKnCcBiNG7ThOErsNFRmqoSlfXYRuqAL4Y0JeUJAwfqKA85vybUePTv8IftFFXNMcA5bfQVS1qZCacgVt15lAcOL5X25XE1ShxRYuKpgn+quvSDH1Xwwi3MWEzWqH2Q= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL1PR21MB3377.namprd21.prod.outlook.com (2603:10b6:208:39d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.14; Fri, 29 Sep 2023 18:20:30 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::eff:aea7:be24:8e44]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::eff:aea7:be24:8e44%4]) with mapi id 15.20.6863.013; Fri, 29 Sep 2023 18:20:28 +0000 From: Michael Kelley To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, thomas.lendacky@amd.com, sathyanarayanan.kuppuswamy@linux.intel.com, kirill.shutemov@linux.intel.com, seanjc@google.com, rick.p.edgecombe@intel.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, x86@kernel.org Cc: mikelley@microsoft.com Subject: [PATCH 5/5] x86/mm: Add comments about errors in set_memory_decrypted()/encrypted() Date: Fri, 29 Sep 2023 11:19:09 -0700 Message-Id: <1696011549-28036-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1696011549-28036-1-git-send-email-mikelley@microsoft.com> References: <1696011549-28036-1-git-send-email-mikelley@microsoft.com> Content-Type: text/plain X-ClientProxiedBy: CY5PR22CA0048.namprd22.prod.outlook.com (2603:10b6:930:1d::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL1PR21MB3377:EE_ X-MS-Office365-Filtering-Correlation-Id: 5adb1059-6f53-4d32-53a3-08dbc118c226 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ouGYYtscQdmWdHNkVkNIdZFc7CsuapPc+oOvplRgkTiM47ucJ4BG1lCNWQeEALEDGP339wnlcaapIhcfdJOc0QUZ+17S2kqkx5ArlVikCEbqCgMx1goKg9EVp9yZYQ9+keTbemtx0h02euq2M8VWHF9cu/i12GgufKk2zDKTPjR0OK38HipvQUEhIK5mt/9Vkj5ht9Hf0ufUj9RdDmaERHllp/t9e+OylUm70vNQGLZ+eF1Vm+SlmeyERupaYsXEARB7O5QbMB+1W/MUPAv7zojPPbIiZscycEZDY21+TduDD56gHF74mxYLdFhT1OU4oyWNa65Mu4iFXNVVYMwMPMs+MBSjsAuoNzCTO1LK4ZbeR4FdYTyFEpPiEERBy8/NgqTZg9qTVFUtsmowhA5uoBjQBF+KOBzFFmJQw2DAhxneWjBkSbHp51YBKcZcWSahP2fOK7Dr3J9QjTMqcwKjO95Su6ZJAE/s2anGdFSFn2SjRbzQyw8OG9XGYPjP0cEVO90Dtwhfza6P+DbJAZ+qjBFnf51KDWPQsUSXmlMm/9fnGruFcjhN7D2wK9La5tRmuC0Ug5rLsNjZNU/qtAgqyTtQAL3g4wyjE/Q3mpVoEC9vmK4a1+UmSy6aHifde/0asvbGP+BDQnoQblXgJrBS7Gn9Zu5Csp52Cb7PlxQGkjyW5NGrVb6frYo4EjWeOhSE X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(136003)(346002)(376002)(366004)(230922051799003)(186009)(451199024)(64100799003)(1800799009)(41300700001)(6506007)(6512007)(6486002)(52116002)(478600001)(6666004)(2616005)(2906002)(316002)(66946007)(66556008)(66476007)(5660300002)(107886003)(10290500003)(8676002)(8936002)(4326008)(26005)(7416002)(921005)(82950400001)(82960400001)(36756003)(86362001)(83380400001)(38100700002)(38350700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?KXQiH35tJcQE9Qa2lan00MA3iwOfYBoa2t1AYKjbJuJueU+5CHblXJcqCwGq?= =?us-ascii?Q?wrOA5U7rHdZ2Tk+JHggjcBYJkgPBJE0RjoxzBZLWL+5J0R9hUb/EjoxoDJTQ?= =?us-ascii?Q?H5qkQEDzhOIDx6EcbPcvB3w32TUxbLx5vEaF7cr9S7NObXmWtq4wscu2azQn?= =?us-ascii?Q?/SFN8zunU58YG1z1Mu7TUWOBI2/6tlqKKf6oRSvhGCE0Hbw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sA5H0IMzvdz3pQJ28L3h/FjOsgZ+TFdIG?= =?us-ascii?Q?BtpZpwiXh5PcbbXrd/vZoUFXYcuUqTEemIgQ0WR9gPXiZ3YG+/37CVdn7Okb?= =?us-ascii?Q?QZ56upt2OvtY5TbiLbdDXvtsB8kWoROxrUXrfi/QL8Cz6pWSPDNvrgT3Ranp?= =?us-ascii?Q?B58mC/qc3Jl4GmJZh9URs21NPcvsbK8Kw4eyjs9Z3hRoZ2h7Cm47X21qwWzm?= =?us-ascii?Q?p+YP+Lu8crkGI1dIzDLS+pJW46KS6gM5V8Xl8/J8zI1mxOD12njkwfY5WZ74?= =?us-ascii?Q?HAv/Heq3qM5hOAE+dPc8nNoAU5izgQVcPdTkaFtu/Rx/IwM3R7Yy/QykEuIK?= =?us-ascii?Q?yE/ycKKjNLfC6vGNrQDNfmIYdXemWiXQSS5paKm6dsDHcIcoeMsvJIeoQ5tW?= =?us-ascii?Q?UNcKc2OaeIIEjLGgveoqy7CbUJBTdxjFeuUZ4qA0LXKUmGRvdisGsFKjQ9bF?= =?us-ascii?Q?bWdih3/KrsULXZ4qScasbKB044U/IHSpnKPlG3Yrw6ByO7M54i/nTFkSogcu?= =?us-ascii?Q?nA=3D=3D?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5adb1059-6f53-4d32-53a3-08dbc118c226 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2023 18:20:28.4964 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yuC0/ng7YRMFlSH624x5Zh4tbrDZw54JUc36WXS5nWvZrTSeIOYq68BecXjwtf3CMKRPcpMqy4Ju4b7WlGhsgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR21MB3377 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 29 Sep 2023 11:21:32 -0700 (PDT) The functions set_memory_decrypted()/encrypted() may leave the input memory range in an inconsistent state if an error occurs. Add comments describing the situation and what callers must be aware of. Also add comments in __set_memory_enc_dec() with more details on the issues and why further investment in error handling is not likely to be useful. No functional change. Suggested-by: Rick Edgecombe Signed-off-by: Michael Kelley --- arch/x86/mm/pat/set_memory.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 1578077..9d07d4e 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2133,6 +2133,24 @@ int set_memory_global(unsigned long addr, int numpages) /* * __set_memory_enc_dec() is used for the hypervisors that get * informed about "encryption" status via page tables. + * + * If an error occurs in making the transition between encrypted and + * decrypted, the transitioned memory is left in an indeterminate state. + * The encryption status in the guest page tables may not match the + * hypervisor's view of the encryption status, making the memory unusable. + * If the memory consists of multiple pages, different pages may be in + * different indeterminate states. + * + * It is difficult to recover from errors such that we can ensure + * consistency between the page tables and hypervisor view of the encryption + * state. It may not be possible to back out of changes, particularly if the + * failure occurs in communicating with the hypervisor. Given this limitation, + * further work on the error handling is not likely to meaningfully improve + * the reliablity or usability of the system. + * + * Any errors are likely to soon render the VM inoperable, but we return + * an error rather than panic'ing so that the caller can decide how best + * to shutdown cleanly. */ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { @@ -2203,6 +2221,14 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) return set_memory_p(&addr, numpages); } +/* + * If set_memory_encrypted()/decrypted() returns an error, the input memory + * range is left in an indeterminate state. The encryption status of pages + * may be inconsistent, so the memory is unusable. The caller should not try + * to do further operations on the memory, or return it to the free list. + * The memory must be leaked, and the caller should take steps to shutdown + * the system as cleanly as possible as something is seriously wrong. + */ int set_memory_encrypted(unsigned long addr, int numpages) { return __set_memory_enc_dec(addr, numpages, true); -- 1.8.3.1