Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2541303lqb; Tue, 28 May 2024 03:15:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUx93BTiK13kODJET9f9747D/uuTPWYLahh/2oO6iDVAUbUcYwTLZsGG5+QCU64I4rRHZQKOr9uAEQZJVWhG0EeU9wjs4ZNOZSSXXoJDw== X-Google-Smtp-Source: AGHT+IFJa7k3ktP8oivTjKjsHb0b5w4NImy/6Bs43UzQkPwFIWfUuSIrldee2JYLMR6LCaY8g0aG X-Received: by 2002:a81:6d86:0:b0:61a:b54d:5925 with SMTP id 00721157ae682-62a08ed9fb1mr109367957b3.38.1716891323918; Tue, 28 May 2024 03:15:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716891323; cv=pass; d=google.com; s=arc-20160816; b=QM/docC+beNSaxUFX5t2GHdKxuDDwydCqeHMRBfC/QvoAhUBPOmEeljTJSuG1Fugaz 8K16ZAJujy5ogt5BSmYg3/y5A9DI7OvQsY97LD4YOBKwgDvPsDuG5ZHVNp30pwFVs1c6 HG/60Ce6Q427s6FM2K85fmYZsHiCv93ZS8ww0NaZojXV5tj7CLl6scFTRadO/ScPR1tw Ax4+AxKEGWEnEjQT4xjW3GB83MiQU6WG76RmR8vyU6odaOh1Rp4IWgW2VAPmON+pxAk6 hI7Mw8Pdy6iMGKIjThktdNV6yXxCL3ybg1uBRLcBY590OTxKe4c5IfH2lumEgy672tuU w9mA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=KJo11HxnJz9bNWmT6d/DDh++L1djwhjY6e39n68+9tM=; fh=rlNx2dm4Qki5fxj48EFV66gh/oqCDPdmRD7cfRwE8/g=; b=c45tYGLzd5c2gbiRXKF+OUSV3TXfapCQIbNQSCO97DrHEZxjaGxal3ktrYzqploar9 AQR00KSO+t5JGp0tkP5UY/SGHKG+eT9E/Q63CAgDMpFKYcH4vh3qA2jXr0kfJMpqy+as zb5aXM6LcrSHtVhM0hW2Pbs3tQFbfusIkV2CQUkn6CfT8KAdoJabui+KIDZfr+s6Vcm0 Ks7vbAzthGNm641uglx/1hjfHpqzoUgpldF995ysCURT9fG0Lf501phwUC2JWC6PbyZ+ 4+GRoYM66lIlbslR7Mr5buiEuwpJSKHqNXXjneu6pAhGY+KL/6ZQ75RqLv0IbyLfPjW5 tiPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=iEW19tZ8; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-192087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192087-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-794abcab985si987086885a.24.2024.05.28.03.15.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:15:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=iEW19tZ8; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-192087-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192087-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 925531C2216C for ; Tue, 28 May 2024 10:15:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE2571649CF; Tue, 28 May 2024 10:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="iEW19tZ8" Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D20613C80E for ; Tue, 28 May 2024 10:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716891315; cv=none; b=CXcGKEI/GlV0OgAtUNMkATAJLwK3NEEV62S/Hcul4n3TkH2HrowW78UhRks9S3garz04e86XFxnZ9PPe2jcI3uAKg4GWH6yHeTEGaFodNrPL7jsY3S8sXadkA+NbpCw0HcoOGjFvHUC/heiPGJCn0l+IyPFp60XRw+s3yxY3Gt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716891315; c=relaxed/simple; bh=E7sKFLfev1mNkIg5WjRCuKqrgXi1JgkmqpVqr6lz4Bs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HwOD7cVfhEZ7FeXSXdKHxunJiVpOHwNmG/lCemxG9v5bQQsii8mzUZxghr8gxu1T0EVoJHfOewPOvTePhlsZZKvHF2qa+OzV0idGo/2K50oMa72gQNQGNLj+NG9MzrJf6t6qlb2viEAkCtSSazKWNLPRB56z4xqxcN4+BmYSg1k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=iEW19tZ8; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2e97d6e7707so207901fa.3 for ; Tue, 28 May 2024 03:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716891312; x=1717496112; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=KJo11HxnJz9bNWmT6d/DDh++L1djwhjY6e39n68+9tM=; b=iEW19tZ8ty/EWCD26onWEnqxICI99g3aN81564s9xkENO7t7zMXn9qXSCDxWAG1lPo G3D2/22QvPa336pHIyPoPdGLolsgxBAg1lDON6ncIph2TENlljhMLMCTh5NS1F0Ztx/G 4LgGo7WuQS4WebmtGkgKRuVmkMGc2Vuq64Vc4vMoOMYGYeiI3OCsHwvqhOXOMJcYIbtp lX9gXNcmuZz9NUXyZcJEPpmwUZz2LkrDFYvXtW4Vj5HXy5gb7cGOuOMk0gO0lII0MeHS a1fK/IeCOD9WgTbz78C+uprrAuFY1ckvvivtFz0Go+n6dAbBVfDj6Qtqs8tx93SwNKWj 4t3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716891312; x=1717496112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KJo11HxnJz9bNWmT6d/DDh++L1djwhjY6e39n68+9tM=; b=GHteTGsiJqI5gC62yp+ZT/cAP2y1I2Vh7b+y62L57fD2d+VHlHPh6zTwVNAts1A/A2 M2Exf5K8r2KiWGQzG2Rq5x9SLwqXwmD4myTEW2JWEiZ0fYOCUcnA86vLL5+/wc78LVRT af6AMyvZ36jm07GON8M2is2BuL1Ot9M/kCfOZ8EeVJREHj97Kz5Tbq6UP1RMebPQYSxj m1ACXR79XllSPMlUpaOZJwn2H+TDxigc6xL+PHOqKNcpbGx+w+bgTd7m0rLdUMQ7Zw6G xol2laHGGw3BcgQEgalmTnS2ozH8Sp2oKiGlKqj7aKh5orvrxNBo4rP0t+Wc2mGPF5qU BwmQ== X-Forwarded-Encrypted: i=1; AJvYcCU6T0OQ8HvND+NRKF7qr/nVhAIVEWZUvN4R3gRIaTtFWJpTReaXapKptRtM32qOLrmJuBfgyXd1z5rLgCUSM9NlEWodY+EKitNVGfeF X-Gm-Message-State: AOJu0Yzy4cTqr6EndOcFIHmATejbuig1iv2srqIqMeR7gglBhD4cc+OR P0+szLl3FlcZrImKijIDZLD4p1fyta+JfiaeWWOVCf7wGhq2OewxLxbfHmyp5vU= X-Received: by 2002:a05:651c:2106:b0:2de:42d0:faf8 with SMTP id 38308e7fff4ca-2e95b33028cmr80465331fa.5.1716891310532; Tue, 28 May 2024 03:15:10 -0700 (PDT) Received: from ?IPV6:2a01:e0a:999:a3a0:deaf:e457:42a:ab9? ([2a01:e0a:999:a3a0:deaf:e457:42a:ab9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35586a15f56sm11303694f8f.109.2024.05.28.03.15.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 May 2024 03:15:10 -0700 (PDT) Message-ID: <40da6797-faab-41f3-b4bd-766e6a117468@rivosinc.com> Date: Tue, 28 May 2024 12:15:09 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v4 4/5] RISC-V: KVM: add support for SBI_FWFT_PTE_AD_HW_UPDATING To: Yong-Xuan Wang , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, alex@ghiti.fr, Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org References: <20240524103307.2684-1-yongxuan.wang@sifive.com> <20240524103307.2684-5-yongxuan.wang@sifive.com> Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: <20240524103307.2684-5-yongxuan.wang@sifive.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 24/05/2024 12:33, Yong-Xuan Wang wrote: > Add support for SBI_FWFT_PTE_AD_HW_UPDATING to set the PTE A/D bits > updating behavior for Guest/VM. > > Signed-off-by: Yong-Xuan Wang > --- > arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 2 +- > arch/riscv/kvm/vcpu_sbi_fwft.c | 38 +++++++++++++++++++++- > 2 files changed, 38 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h > index 7b7bcc5c8fee..3614a44e0a4a 100644 > --- a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h > +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h > @@ -11,7 +11,7 @@ > > #include > > -#define KVM_SBI_FWFT_FEATURE_COUNT 1 > +#define KVM_SBI_FWFT_FEATURE_COUNT 2 > > struct kvm_sbi_fwft_config; > struct kvm_vcpu; > diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c > index 89ec263c250d..14ef74023340 100644 > --- a/arch/riscv/kvm/vcpu_sbi_fwft.c > +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c > @@ -71,6 +71,36 @@ static int kvm_sbi_fwft_get_misaligned_delegation(struct kvm_vcpu *vcpu, > return SBI_SUCCESS; > } > > +static int kvm_sbi_fwft_adue_supported(struct kvm_vcpu *vcpu) > +{ > + if (!riscv_isa_extension_available(vcpu->arch.isa, SVADU)) > + return SBI_ERR_NOT_SUPPORTED; > + > + return 0; > +} > + > +static int kvm_sbi_fwft_set_adue(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, > + unsigned long value) > +{ > + if (value) > + vcpu->arch.cfg.henvcfg |= ENVCFG_ADUE; > + else > + vcpu->arch.cfg.henvcfg &= ~ENVCFG_ADUE; > + > + return SBI_SUCCESS; > +} > + > +static int kvm_sbi_fwft_get_adue(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, > + unsigned long *value) > +{ > + if (!riscv_isa_extension_available(vcpu->arch.isa, SVADU)) > + return SBI_ERR_NOT_SUPPORTED; > + > + *value = !!(vcpu->arch.cfg.henvcfg & ENVCFG_ADUE); > + > + return SBI_SUCCESS; > +} Hi Yong-Xuan, vcpu->arch.cfg.henvcfg seems to be used to update the HENVCFG CSR only during vcpu_load()/vcpu_put(). So if this extension updates it there and stays in the execution loop (kvm_arch_vcpu_ioctl_run()) then, it seems like the HENVCFG CSR won't be updated immediately but on the next vcpu_load(). Is there something I'm missing ? Thanks, Clément Léger > + > static struct kvm_sbi_fwft_config * > kvm_sbi_fwft_get_config(struct kvm_vcpu *vcpu, enum sbi_fwft_feature_t feature) > { > @@ -177,7 +207,13 @@ static const struct kvm_sbi_fwft_feature features[] = { > .supported = kvm_sbi_fwft_misaligned_delegation_supported, > .set = kvm_sbi_fwft_set_misaligned_delegation, > .get = kvm_sbi_fwft_get_misaligned_delegation, > - } > + }, > + { > + .id = SBI_FWFT_PTE_AD_HW_UPDATING, > + .supported = kvm_sbi_fwft_adue_supported, > + .set = kvm_sbi_fwft_set_adue, > + .get = kvm_sbi_fwft_get_adue, > + }, > }; > > static_assert(ARRAY_SIZE(features) == KVM_SBI_FWFT_FEATURE_COUNT);