Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1562049pxb; Fri, 20 Aug 2021 08:23:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdepX5QYV5HMIX/JHFXGbFAA7Yg9J0ffGSUF4JEjuzQ+zWOXio40yWKHz9eBVoUQ4Wj5RW X-Received: by 2002:a92:ca89:: with SMTP id t9mr14539820ilo.178.1629473025721; Fri, 20 Aug 2021 08:23:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1629473025; cv=pass; d=google.com; s=arc-20160816; b=G9yS9jVhnH33lTBA0egTTTYLslhRGf30nI25ZVSfszAIdXQcGgOnMxPB8GK93gIVla EhBsS1fsg3Ma6WsBZqGdrSByqvTMuu6fwDj2tPtwbgVgzA5dkqQqZu0y2mXR7u6frk+A uDezP1yRrcK2HsaGJNW6uiFjN/huM1E8m5xQsujPFT+pTG/Y2T1ezXhFX5+t5dRujPyD YUa8/hF1BolgTeA8SkNUxEpThs6DL5GiEXnWfoZNE+QZXzfZX+mJHcM9qook8vuTU13Z g+I3ncnbaIZtWLEB2QLd6bWG4DGug0ILB7ebLcNLARmXYulvyPMuueJmQwg2ZDY228PM YwoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=auJREV1mAE69GKyOzop1JjXtKKGgG6Klxx/V2yHFQ3g=; b=EvgFAk8ygGzJjo0Bc9GhUpY5kbNK5PVM6Bb2l/aFbwKHhSBzpKGPs60fFF68sueBuI sjI21/55jM4746HJ4mabBjQWXfK7KmjV1Hvl6YI4NX9/lwzYaGu0X8AG3vafBgcmrwro yLPc2Zlk4Oc0BALjF9dw/Wud47VMdXLFe7MRg96iBUm2Y8Ts/UCBFnwdJYM18ArWyPfp PeL1SB85ngTqlBuo+sdHrsSHUh88KrmLDQcwrem4bK5x6H568s5bBh+PCrDOJJBuJ0wN AjzmIPBxtdp3NyKnunBlkbjaI6NvMpORU/+s7CLE0JiYe6Who9mCPcFkZgIByk5hiWZp 8Thg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pqWF3Nbf; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r13si7349906ilo.33.2021.08.20.08.23.34; Fri, 20 Aug 2021 08:23:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=pqWF3Nbf; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241170AbhHTPWl (ORCPT + 99 others); Fri, 20 Aug 2021 11:22:41 -0400 Received: from mail-co1nam11on2059.outbound.protection.outlook.com ([40.107.220.59]:31347 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241272AbhHTPWL (ORCPT ); Fri, 20 Aug 2021 11:22:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HfoMczt1+451JBaWK/NiipIxXebYxNNTedWtLrVSgRk9KeZzacm0hkeys/W34WB+sHmPchbin0pSuHyN86YCkEQEq3hBp48yoe1CO035W+gMTPuw16e6Jf6ppnRVfjWvg6oHKOqRBAT5dwWxqQPVJal56FLtVAo35lwARWceAT9QbmmCOCZPXEyzQBwc073ge8FGsDV2N1buTfIQ6UlGvWMhSLfS/Y/iklF0Z3FPd1mMf2AdkABjMKpF/CEhWLg7SzIlIbfdiBcGAv8lKGrDKgJ8mhwUFFJG5R1yuTUL+XjZGQ75aWVCmtFUBAmdJ2grDS0LWt5PCI/eP9czXTNLTQ== 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-SenderADCheck; bh=auJREV1mAE69GKyOzop1JjXtKKGgG6Klxx/V2yHFQ3g=; b=RsVgovd0vt9/mNNu60YCCQVK9t3KU0e7NU6P5Re6eTJkFZtkkW8EZgmVBfORSXTSWi9dnd4bTkhE6+65lvKMvI31Rq8WlQzoJnMrR6rqo11v/HoxHvjzip0Oe809ecKULKsPgbwxL7OL6Z5Uc4R7+V2kC0LaafFiLyDYDu8s2uILvfvElcJZgb/F/A6yyTsp5yzqVvMri4QtDxZU0m4KmfdRximb/7ivBvmcX5zUmceCFqiXL7lYx09hTF9h16bCL+NNFjYgZ4orlAOBWYYGQK9T4+4xVJKx6ZUbvqnmJjvIdr9/tVlfBxtAtGMVfT/uqPfAAt2GaK4zKugTlGYeXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=auJREV1mAE69GKyOzop1JjXtKKGgG6Klxx/V2yHFQ3g=; b=pqWF3NbfSqkis52praMqadny4to4lBJ3hVfH8QLgKtWwO6brMlw+VqnzEb83xvM3b+WQRH7aT/ZNDdOYJN8B+tiIYsZFa5yPn6Slhre2roIciqqR2fqM68z5mZUhQD7UQcCK2JrPy3OqIHu3DLskXHUm5g6EVUGRCS6/gF3zhUM= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 20 Aug 2021 15:20:59 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4436.019; Fri, 20 Aug 2021 15:20:58 +0000 From: Brijesh Singh To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, Brijesh Singh Subject: [PATCH Part1 v5 09/38] x86/sev: Add a helper for the PVALIDATE instruction Date: Fri, 20 Aug 2021 10:19:04 -0500 Message-Id: <20210820151933.22401-10-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210820151933.22401-1-brijesh.singh@amd.com> References: <20210820151933.22401-1-brijesh.singh@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SA9P223CA0002.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::7) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9P223CA0002.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Fri, 20 Aug 2021 15:20:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 19f61b4f-680c-48b4-9dfc-08d963ee1cdb X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7SE3PBf2cG3x9f+g4a5lKM0BZNlC0PPT8cJ+ItgL9QBTDwTogzzuiuz31stZ1C3RyqDqohdCnifRIJimTf+bdukOkkhNuxzPkJmqlajZhMDYyJU9+7q4jnTsU1QBOhonoqGC/w4U1TFxOqtQP9m9JZ/0/GiorzK1UO9UWWVrSSHRLsDeXvZy7iRPMNmCiyzXWlO6CLNDOm+DBvhJVfTjvmWQJdgF34cwpkDRyCfbzt5Kytw//iioaxF1gCb+343lfRolnxzZFPROLO8HtRqTAkYs/IzlPo26kDT6tJjkaKhsE9sOfBOMmFz2uAItVYq0qXvIleVa4G4AJ5qBXQ3rP0ijunB98fZUjf5fPcAn6mTvu38R/zO4IuYxhDu3YZMR/JVVIz8GEO7XC3iVqV0E3PcfThFn/5gtcLY8utbjW+0xV1hXlvzlvV0y8Nj9K9qbqBCWcBWOkBIHqEocRhw+N4zz+HGRCHhaxuYlt1zIaaQ2H5N3yTePTs79g7uXWiFKeedOaHYPd2mtgxcpR3h+12P5mhHEQG3y+tQzx7rBBu670Wza4+8K/rCdfhjP8J1S0b7NTue5dCOKiCXNJTQx7g34qixgjYWA3N59TaZuxdbjTPjXpIWvFjAXkphc6ivIjK72l9YQ/aGHBFhXpEg/JjPIiRragt5HJzEfGrMEz3lE5FP2aP4ciXBHWcPLFc0O X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(396003)(39860400002)(346002)(136003)(956004)(38100700002)(38350700002)(8936002)(52116002)(6486002)(478600001)(8676002)(44832011)(2616005)(66476007)(7416002)(66556008)(7406005)(2906002)(83380400001)(66946007)(5660300002)(54906003)(316002)(86362001)(6666004)(26005)(4326008)(186003)(7696005)(36756003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aExXWVhNUmNSYkZxWGRWL1JCclZTZHJKbUR6Y08vWjNUcytFY1FCT05IYmpl?= =?utf-8?B?ZlFDbXYyMmxZYzhzVnRIZFVxTVRmRmFwOUlpRTV4Q21TNG8rSVVmVjFUa0VK?= =?utf-8?B?MUV6ZVlzVWVqbkxBZGFQYnVLVGR0eVBwc3ppUkFyLzhNUmhrOXUrTktPNkZw?= =?utf-8?B?NWc2RnlTdjVTNXdQN2g2WmJkSDZVb0VNTlRlV2dzRWsreGlpL0QveDliOXMr?= =?utf-8?B?U1NzZldxdDlTOEN5dzQ1RnBEZ0x5QXJiWm1JaTJjeWg2MjRQZXh4MDgzN2Yx?= =?utf-8?B?MjB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FZWV1Z3RUQkpYL3lGWE9wWjRJcktCcEhDTWZwNVNGcUpKTmw4SHVU?= =?utf-8?B?MWN1QkJ3d09ZMng5MkEvNFR3ZDlFWHhHaDBFTEVkelFZaXhMcmZVWVlEZVBh?= =?utf-8?B?aFIzNlBFZyt3NXNXbFIrbUpJdzZibmQwc2NNVXhuSFJmaGJ3S2N1aGtVZm55?= =?utf-8?B?MkxrcEdCTS9CZDJwekVSZnB6TjRrTVhHZlpyejlwNjJ5Sng3cnlvSTdwTDFT?= =?utf-8?B?UTJrNmJvSHhYSGlvR1ZMVUpHMFBpSVhDVGxTV1dnWEZ5cTBsOXhnL1NRbkp3?= =?utf-8?B?NGJaT3hITlIvUWF2cXpLMmQ2S1Z4bVdWQlBaNUJkTjZhMWJPbTJUYWxLVVBu?= =?utf-8?B?Z25nelN6VGVLWHV1YTV5aksxd3diZE5DK3NuZjFseGh0VkZKRlJHdjBtcmxw?= =?utf-8?B?eXFQTmVublhBNFRQMXlJU2dJV1N3VTI1V1E0UUxxZ0ZNbm1OQjAzYk8wc0p5?= =?utf-8?B?UlBiOVZUZmg1MVliVVhpaVlaTzIxdFRlaURSWGhvWDBQN2hQTndqSW83bGJp?= =?utf-8?Q?kVGKgcB815VSloSHNEedOWl0j5NtfP65PXKoU2J?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19f61b4f-680c-48b4-9dfc-08d963ee1cdb X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2021 15:20:58.9015 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mvycn0ITVwHVl1zVYwIaCgPNEoLGPQg+s7vLX89vwQclifwDaUHtSMPf/PjjsJf02bgz9AyhF+/ECUHihZzvrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An SNP-active guest uses the PVALIDATE instruction to validate or rescind the validation of a guest page’s RMP entry. Upon completion, a return code is stored in EAX and rFLAGS bits are set based on the return code. If the instruction completed successfully, the CF indicates if the content of the RMP were changed or not. See AMD APM Volume 3 for additional details. Signed-off-by: Brijesh Singh --- arch/x86/include/asm/sev.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 134a7c9d91b6..b308815a2c01 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -59,6 +59,9 @@ extern void vc_no_ghcb(void); extern void vc_boot_ghcb(void); extern bool handle_vc_boot_ghcb(struct pt_regs *regs); +/* Software defined (when rFlags.CF = 1) */ +#define PVALIDATE_FAIL_NOUPDATE 255 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key; extern void __sev_es_ist_enter(struct pt_regs *regs); @@ -81,12 +84,30 @@ static __always_inline void sev_es_nmi_complete(void) __sev_es_nmi_complete(); } extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); +static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) +{ + bool no_rmpupdate; + int rc; + + /* "pvalidate" mnemonic support in binutils 2.36 and newer */ + asm volatile(".byte 0xF2, 0x0F, 0x01, 0xFF\n\t" + CC_SET(c) + : CC_OUT(c) (no_rmpupdate), "=a"(rc) + : "a"(vaddr), "c"(rmp_psize), "d"(validate) + : "memory", "cc"); + + if (no_rmpupdate) + return PVALIDATE_FAIL_NOUPDATE; + + return rc; +} #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { return 0; } static inline void sev_es_nmi_complete(void) { } static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; } +static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) { return 0; } #endif #endif -- 2.17.1