Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4964947pxu; Thu, 10 Dec 2020 09:33:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzck4mXO6P0xiolMXG2P22W80qc/ZOysX97GE2Pv4WZEne53SUVR6KR6m95PMRKkkRDiGI1 X-Received: by 2002:a50:b243:: with SMTP id o61mr8059536edd.57.1607621604244; Thu, 10 Dec 2020 09:33:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1607621604; cv=pass; d=google.com; s=arc-20160816; b=ddhG7IXzTiiS24LACIeU/BFWItr6HDkHMQZZ973FoyEMwqsS062R4rpsxPAALVecY5 EGJOC6hF7UA7uzTFCz5ZqCl8tmhs0sH7iBs+/SsBYH/0e9T5QNprT+GjB2rE/tcNXliE se3+z2e8EYpXz3CrF+g2r/MJkFpIoImeZO+RlAQqsHZcVSrZHS8IlEsGlUOCkVuooEnr PjmM+W+3C93njx8fUXaIgODPwfAMDZwQojKo7H/cGx9zSUxopKtUapxMM9UMk9Imu1uB rxrrJ9AZa9KnEE3hQya6I8Y5vIF5omp8AJskYuge2cQSR+ZEtMklzif5g8Ydp88ndwjn D4lw== 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=Rdrg9xdmCo1Mi+20Ub/bjG9z6mIYPEDGliwugujXITg=; b=zJHr+24F/vggko7TcrpI9w3MIP5tTmpin/VDKASSelxVAcQ9QolM9ifM0HdCow0JWF JX3AJPdFsgva63kC+MVo4HNLvpnD3R0nc15uDU721me7VPYnXllxG1ct6L613maEnFv4 CvU0RxFiQWq1HPSP0+qfdlyE/erXDMUAqjiVO75skiHpCLaGAt+y0HDS4E5FMPBr+YoM Hp/XWqVkHAONrgKMg0bVuuaIOXf/AtyO+RxO5MQaq1zfaQCz0gqubF4eI7yoJuJDznAk /V2YxxurwPd875Ocyhg9rgWTaecWpa03dXz5egU8RleXq5vwFM8IedM3aYRgVrPnCxZ9 h86A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=TwGOrA3a; 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=fail (p=NONE sp=NONE 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 np6si2876026ejb.609.2020.12.10.09.32.56; Thu, 10 Dec 2020 09:33:24 -0800 (PST) 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=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=TwGOrA3a; 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=fail (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392637AbgLJR34 (ORCPT + 99 others); Thu, 10 Dec 2020 12:29:56 -0500 Received: from mail-bn7nam10on2082.outbound.protection.outlook.com ([40.107.92.82]:61760 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404135AbgLJRQH (ORCPT ); Thu, 10 Dec 2020 12:16:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZnAS2i/5FjP9//XOAWQhco90/gcyjowJMJO5LulC4t+uII40nlUMhUc61ZlJLsv92kxbnuC9a61iJ3qoCd3POK4BsTDb/TcMV5ORlvbH3/LUm8+LlPKwglOGw3z7IBN4bAvDl5DWq/VPvtnd+BQYMK5fy9BR+3JtYZwe96RyoCf+o26s2iDXeoK5DCeCOQdNlR/s1aWgbEg2LbHd/O1jZfhMXrRD/f6W63/putMY9Y90v0GB8nsoMF/mZ24doWuzqyXejHcIARg3ORLnF7Cad5DCowEHrabK6oD95XUKdhCGDDMRxTfF85b1dtnB6XCBnzTZiC7N1A09M7iVBKDb3A== 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=Rdrg9xdmCo1Mi+20Ub/bjG9z6mIYPEDGliwugujXITg=; b=Se19AMLYJFp9pjIR21wpX/DOrtND/AfjTxnH6GfAfNNG7Dzf7XjOR3yQ6/WQn5BSE2KDg409w74QxJWOkLAaQEJyiIEWvZs8c8XINy2eGa2XaEYFS4KL1nDN2FF9pTfmbpai+Uq9Rt9DjyOo4Wd3Q6qYa03t/zxQXK+Td5iJWuuMJKijdTl9A8Jzysx+kTIjebmxpQz0VbXAKwbiJwiQso2BtRWkfgWCgUEyfrO4vqRUN0tN2hBHYj6DJ/8rH/r+bkn73VNv1VRkVu5lHB/T8IUYTYx6sXraxLeqjitRDSxSj3Rm4wHbcFQritr6LhmXQRizEHxYhmjACi/Pt1i93Q== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rdrg9xdmCo1Mi+20Ub/bjG9z6mIYPEDGliwugujXITg=; b=TwGOrA3a9F4pBzd4sqAeJ31Mizi6j3RziARWVB2EUKsIn/PrKAVNImZRyHbkFNTAoXHnrC/IoVaUJz3YHQTc2ozD5YtLOILqabuuwXVgH2x4ZKLckiburaHGuIJRy6Op/OuI+ZpLX/Jpn37JBXF8xVzWBxauLRAoQXVC1YBBWfs= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1350.namprd12.prod.outlook.com (2603:10b6:903:41::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.20; Thu, 10 Dec 2020 17:14:49 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d%8]) with mapi id 15.20.3632.021; Thu, 10 Dec 2020 17:14:49 +0000 From: Tom Lendacky To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Paolo Bonzini , Jim Mattson , Joerg Roedel , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Brijesh Singh Subject: [PATCH v5 30/34] KVM: SVM: Update ASID allocation to support SEV-ES guests Date: Thu, 10 Dec 2020 11:10:05 -0600 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CH2PR05CA0042.namprd05.prod.outlook.com (2603:10b6:610:38::19) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by CH2PR05CA0042.namprd05.prod.outlook.com (2603:10b6:610:38::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.5 via Frontend Transport; Thu, 10 Dec 2020 17:14:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1030eceb-cbe8-4d4e-7480-08d89d2f19c1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1350: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eSTRoIAhqVc5sE600OVW/eKO/YCFlzxpUFO6+eitTx8fytW+MQ3bu+xUpDMzjYl7xTSkTt/b69QQH9awEaaTSy3iMaUJ9t6GMDB+9q1U/G3j7KJlHS2CpcMq0qtIc0Du5qw7J79r9fPPkqL0nbP3fdSsdxqC/J0gm2DAymOPdK5m8FKiwobpO4bs3qWSt1AWFAaAF95Du6MY6KH5uW680KlfuhRPym09HCDMIoei+oDbgdeZtyGn61tUGswjofrrc/RNi9S0AGZPfGYnd6SaHyla0ImhNSoU/EiwniMOaeNjvwmwqEahrjNR4ZqXP+W+Yo/oA+sHZkpjfd4vg0GXePx+vyWFjWds7je4V3YK9/uwQzVY81gKlwtVVrht8Qeo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(346002)(136003)(6486002)(8936002)(16526019)(2906002)(2616005)(54906003)(508600001)(86362001)(52116002)(66946007)(36756003)(6666004)(8676002)(7696005)(83380400001)(4326008)(34490700003)(956004)(26005)(66556008)(66476007)(15650500001)(7416002)(5660300002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam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Wnvu8bmFiwV+tL8TXv3629NmQJP?= =?us-ascii?Q?+QMvLstEvXiz+HNK/7YLG9WZy0oKyZeQchnO29Zk9yf0YAammhUvfJ34crJx?= =?us-ascii?Q?07e9R/ziZRkqhHuZmd9nKfpWL/d85gWxNK5bXfXZ8hc23FpOBDYtN7ZKHo/5?= =?us-ascii?Q?BP4f?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2020 17:14:49.3257 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 1030eceb-cbe8-4d4e-7480-08d89d2f19c1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8d2YMUdpVnwL/GB8YIzeS6ob0fRZB2obEKfauDshwuFbVzHbhVWmgs5vXqZxkpOTLWImwZCFcLPrS8VYImq5YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1350 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky SEV and SEV-ES guests each have dedicated ASID ranges. Update the ASID allocation routine to return an ASID in the respective range. Signed-off-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 4797a6768eaf..bb6f069464cf 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -63,19 +63,19 @@ static int sev_flush_asids(void) } /* Must be called with the sev_bitmap_lock held */ -static bool __sev_recycle_asids(void) +static bool __sev_recycle_asids(int min_asid, int max_asid) { int pos; /* Check if there are any ASIDs to reclaim before performing a flush */ - pos = find_next_bit(sev_reclaim_asid_bitmap, - max_sev_asid, min_sev_asid - 1); - if (pos >= max_sev_asid) + pos = find_next_bit(sev_reclaim_asid_bitmap, max_sev_asid, min_asid); + if (pos >= max_asid) return false; if (sev_flush_asids()) return false; + /* The flush process will flush all reclaimable SEV and SEV-ES ASIDs */ bitmap_xor(sev_asid_bitmap, sev_asid_bitmap, sev_reclaim_asid_bitmap, max_sev_asid); bitmap_zero(sev_reclaim_asid_bitmap, max_sev_asid); @@ -83,20 +83,23 @@ static bool __sev_recycle_asids(void) return true; } -static int sev_asid_new(void) +static int sev_asid_new(struct kvm_sev_info *sev) { + int pos, min_asid, max_asid; bool retry = true; - int pos; mutex_lock(&sev_bitmap_lock); /* - * SEV-enabled guest must use asid from min_sev_asid to max_sev_asid. + * SEV-enabled guests must use asid from min_sev_asid to max_sev_asid. + * SEV-ES-enabled guest can use from 1 to min_sev_asid - 1. */ + min_asid = sev->es_active ? 0 : min_sev_asid - 1; + max_asid = sev->es_active ? min_sev_asid - 1 : max_sev_asid; again: - pos = find_next_zero_bit(sev_asid_bitmap, max_sev_asid, min_sev_asid - 1); - if (pos >= max_sev_asid) { - if (retry && __sev_recycle_asids()) { + pos = find_next_zero_bit(sev_asid_bitmap, max_sev_asid, min_asid); + if (pos >= max_asid) { + if (retry && __sev_recycle_asids(min_asid, max_asid)) { retry = false; goto again; } @@ -178,7 +181,7 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) if (unlikely(sev->active)) return ret; - asid = sev_asid_new(); + asid = sev_asid_new(sev); if (asid < 0) return ret; -- 2.28.0