Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1847037lqa; Tue, 30 Apr 2024 00:26:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBKpQ4efZzuhS1rIhN7FqGxRkEnqNtSBAcdYaIaSbyRp7M+mGzX6qnHcbpjgJuAKc6uw1SJ4EN8L6sGfD1c9foQQkwzNE6Jtk85LOjGg== X-Google-Smtp-Source: AGHT+IEwF94UHGY28VC8xOiWBsJ890W8moPDDAORPG8/Ym/OjT1Q6/eeOFJoluXNk29sjbJq4x9k X-Received: by 2002:ad4:5c6c:0:b0:6a0:cefc:a86 with SMTP id i12-20020ad45c6c000000b006a0cefc0a86mr1862685qvh.62.1714462006636; Tue, 30 Apr 2024 00:26:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714462006; cv=pass; d=google.com; s=arc-20160816; b=kt0cBSMiAe2DN2vOFP67RMNPT9KdA0MYOm2H6SbTXQqtQOrAsmPyLYNJy3UYZHsBar rM1bFtaGYn16EiMFbxoe3pdz3mqCueQ0gElp0SJjbmn/slhPnpkS24PWP7rxVFC5Z/yl RS763Lzhgzx+C3KQaipaoCP3fOPMn4d9I4wKsUov/cjjzWjBa5B/hZ5xQzCTzaWSYAWZ NVFvuEQRBhgKL/32H0A9zppDLhX81zuJRl63iui7W2Kmc3Su7ZNBQPYJgwKGHKX3U4iL 3VdrmCgFFnk0YfWTlSBeMX0NJUDALrBepGxeskIhMoEXszSXc8cC3MPPw908Ay9Ex0mG 56tA== 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=WvyI3HdmRjoW+CLhdf/TdUb0HyFLPhU7rZbG7Bu9wO4=; fh=eizUBFrvZxotR4CLAfjI19BKuA5Oe/ahXB3Tm+EwyA4=; b=wwfJ//VwcN2AnUe+5ZxHmcVCI5v05lHj6g2B/RTeOl0XjtkuwcFAZjj+q0JfsW0gEw mEUJJGxYiSmfW3mSWTg5YFu8A2na0v+7SvARVuSRC6JFLbPuQM/r6EUUlTzI2kxPsPrf WTit0Yl+DqaT/KB48WwWwMtRtA29O23SXDoP898rhN4jQ8euDZH/6A5/FCbhhxeEWzpY wa8GgXmk/oNyEIOfrD2s2h1kpTolOLlzx5kr4T1ckkorThlnScWsbETB7GlG6jrMngaC 4ca1OIr/Tu3GrcP7geg5HbPyb94tZ/1QLMBblH7g6+RjzflS2b+q2rFmbvcFTO8zTIJi JlRg==; 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=h4abnvZ+; 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-163462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163462-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ib2-20020a0562141c8200b0069b413ebc4asi28481544qvb.264.2024.04.30.00.26.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 00:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=h4abnvZ+; 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-163462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163462-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 366D31C21DA7 for ; Tue, 30 Apr 2024 07:26:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF97C3BB2E; Tue, 30 Apr 2024 07:26:32 +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="h4abnvZ+" Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 642E1374E3 for ; Tue, 30 Apr 2024 07:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714461991; cv=none; b=bsO0ZDM5RUBuWez2Vkn7DJsX6DP1lNpwBAfU9231bf5m8QYbwHLLUuHNO68CaVSgniReTCfwJkN4TLcquVBve/S9YfohUpHe3g0OL+5HeiDzsia1vwHaFJ+SYhSK87FjRE76m0yvjBWcrkGiBraM/W8gahlUVgADm6xTd1qTLVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714461991; c=relaxed/simple; bh=uebO/s6LVxhG0opGGRAkrg4m1oP1SCiyjdL2AO+Foz0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jIJZQ7RtauA1zuCQdnC8r2YG0XMxhSdxyBgSoy7W95Cddo26KeQ1KEYJ5hUTFFOQDg+8lg6wtxesFLQndrkPmZH/EQ4vagjjHrW8pHl4NouSrCWo7xl1bW46+X++W3v0EWTOifsz1aQW77Zq5t+c+YIw9wCv6cq7Sx4tPlnH+XM= 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=h4abnvZ+; arc=none smtp.client-ip=209.85.208.178 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-f178.google.com with SMTP id 38308e7fff4ca-2db239711ebso13031421fa.1 for ; Tue, 30 Apr 2024 00:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714461987; x=1715066787; 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=WvyI3HdmRjoW+CLhdf/TdUb0HyFLPhU7rZbG7Bu9wO4=; b=h4abnvZ+UUUPUnNEAfn90fnbQ2jU1Sh26JF+QCyw2vxc4+gdfjUuTu06iUDBjBls4J T+CASH33Vcc5t10yBvPN9X7HJrWeQaGdbr1V39fT/NssMr9wfxp0lTsHGdDiU6MkEqSX WHb/Eo4hn5zZoR87hzMRyWWvxhaHG8EhUSy5OaTG9dk5fg+Z3w3kz4yvMp8mSEEFAbaD 2O2fqTISYo7tfenKIPubJh+bOq/DAfUs87h2MItFR/kphebbJtnGVoKSLcZBC0SH5YEj P3cJje/DlRZMGiqoM7GKZJSRi9nBXy7cz/W6R4VN1xdStEGuR5tUN1QYpUn8zjol7Oeg f0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714461987; x=1715066787; 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=WvyI3HdmRjoW+CLhdf/TdUb0HyFLPhU7rZbG7Bu9wO4=; b=bSEJXcXUP2MQLnDEjWUFtZ89veFWqmIuz5q66lcRtEDRTNWM1iGdB+rBMadcZXMw2n SKbw/m9/p53AbwxOFIhgDCdJeDtPQUcrSiXSruKDAD+GpyU8oiA1SFYtVZ1YoTuL8VM+ 29jaqOBGUj9jgTxKkxzePTmc8ihBuro2Hic5spyAwRw3uahyrcXe+HZr4hTwi2RFbJuo zKL05Lgyb2XkObGKUoPntxH95NyhYNXbAZwBGqmQmCfcHJuXT5Nm7tG+MH3hJ4v+rIpH nEMreocHP12hO/ZveUgAE78ernPO7v873PlfzQcVThzN2nYsJLqbs3oJKNTYFl/47T1R 4MXA== X-Forwarded-Encrypted: i=1; AJvYcCU0Ni5ZUSEJBNm0Ua6fx+dJNqUIwQ+OPcW8xa234qaQS9eiVVbbbIvgds/mA5aygf/glhM2wq/uJM1XLTJ6N8+d70aOeaIYiYeZuvKT X-Gm-Message-State: AOJu0YzoVLjTWAD/HC+MQYLk0c23UOH72E7SGuKNJPb0HZ2lvbZtePnz vvcZ8pXfUD+ZiV3YeZg/mJD0UmCVPxz5qbJGG8BJbNlRm/R2tfEhqXMwVoE7Ef0= X-Received: by 2002:a2e:9254:0:b0:2dd:374d:724e with SMTP id v20-20020a2e9254000000b002dd374d724emr7481828ljg.1.1714461987258; Tue, 30 Apr 2024 00:26:27 -0700 (PDT) Received: from ?IPV6:2a01:e0a:999:a3a0:c21b:67fd:90ab:9053? ([2a01:e0a:999:a3a0:c21b:67fd:90ab:9053]) by smtp.gmail.com with ESMTPSA id r7-20020a05600c35c700b0041bff91ea43sm9651380wmq.37.2024.04.30.00.26.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 00:26:26 -0700 (PDT) Message-ID: <99d3eabc-0289-4ace-90a8-ad02dbffd6d2@rivosinc.com> Date: Tue, 30 Apr 2024 09:26:24 +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 1/7] riscv: kvm: add support for FWFT SBI extension To: Deepak Gupta Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue References: <20240418142701.1493091-1-cleger@rivosinc.com> <20240418142701.1493091-2-cleger@rivosinc.com> Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 27/04/2024 01:44, Deepak Gupta wrote: > On Thu, Apr 18, 2024 at 04:26:40PM +0200, Clément Léger wrote: >> Add support for FWFT extension in KVM >> >> Signed-off-by: Clément Léger >> --- >> arch/riscv/include/asm/kvm_host.h          |   5 + >> arch/riscv/include/asm/kvm_vcpu_sbi.h      |   1 + >> arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h |  37 ++++++ >> arch/riscv/include/uapi/asm/kvm.h          |   1 + >> arch/riscv/kvm/Makefile                    |   1 + >> arch/riscv/kvm/vcpu.c                      |   5 + >> arch/riscv/kvm/vcpu_sbi.c                  |   4 + >> arch/riscv/kvm/vcpu_sbi_fwft.c             | 136 +++++++++++++++++++++ >> 8 files changed, 190 insertions(+) >> create mode 100644 arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h >> create mode 100644 arch/riscv/kvm/vcpu_sbi_fwft.c >> >> diff --git a/arch/riscv/include/asm/kvm_host.h >> b/arch/riscv/include/asm/kvm_host.h >> index 484d04a92fa6..be60aaa07f57 100644 >> --- a/arch/riscv/include/asm/kvm_host.h >> +++ b/arch/riscv/include/asm/kvm_host.h >> @@ -19,6 +19,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> >> @@ -169,6 +170,7 @@ struct kvm_vcpu_csr { >> struct kvm_vcpu_config { >>     u64 henvcfg; >>     u64 hstateen0; >> +    u64 hedeleg; >> }; >> >> struct kvm_vcpu_smstateen_csr { >> @@ -261,6 +263,9 @@ struct kvm_vcpu_arch { >>     /* Performance monitoring context */ >>     struct kvm_pmu pmu_context; >> >> +    /* Firmware feature SBI extension context */ >> +    struct kvm_sbi_fwft fwft_context; >> + >>     /* 'static' configurations which are set only once */ >>     struct kvm_vcpu_config cfg; >> >> diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h >> b/arch/riscv/include/asm/kvm_vcpu_sbi.h >> index b96705258cf9..3a33bbacc233 100644 >> --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h >> +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h >> @@ -86,6 +86,7 @@ extern const struct kvm_vcpu_sbi_extension >> vcpu_sbi_ext_srst; >> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; >> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn; >> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta; >> +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft; >> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; >> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; >> >> diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h >> b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h >> new file mode 100644 >> index 000000000000..7dc1b80c7e6c >> --- /dev/null >> +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h >> @@ -0,0 +1,37 @@ >> +/* SPDX-License-Identifier: GPL-2.0-only */ >> +/* >> + * Copyright (c) 2023 Rivos Inc >> + * >> + * Authors: >> + *     Atish Patra > > nit: probably need to fix Copyright year and Authors here :-) > Same in all new files being introduced. > >> + */ >> + >> +#ifndef __KVM_VCPU_RISCV_FWFT_H >> +#define __KVM_VCPU_RISCV_FWFT_H >> + >> +#include >> + >> +#define KVM_SBI_FWFT_FEATURE_COUNT    1 >> + >> +static int kvm_sbi_fwft_set(struct kvm_vcpu *vcpu, >> +                enum sbi_fwft_feature_t feature, >> +                unsigned long value, unsigned long flags) >> +{ >> +    struct kvm_sbi_fwft_config *conf = kvm_sbi_fwft_get_config(vcpu, >> +                                   feature); >> +    if (!conf) >> +        return SBI_ERR_DENIED; > > Curious, > Why denied and not something like NOT_SUPPORTED NOT_AVAILABLE here? Hey Deepak, So indeed, the return value is not totally correct since the spec states that we return EDENIED if feature is reserved or is platform-specific and unimplemented. But in that case it dos not distinguish between defined features and reserved one. I'll add a check for that. Thanks, Clément > >> + >> +    if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0) >> +        return SBI_ERR_INVALID_PARAM; >> + >> +    if (conf->flags & SBI_FWFT_SET_FLAG_LOCK) >> +        return SBI_ERR_DENIED; >> + >> +    conf->flags = flags; >> + >> +    return conf->feature->set(vcpu, conf, value); >> +} >> +