From patchwork Thu Jul 25 12:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibo Mao X-Patchwork-Id: 13741887 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8CF2196C9B; Thu, 25 Jul 2024 12:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721910501; cv=none; b=jcNMOKw501Y0da4f4DZuODruqXwlDvTnmBV5pa1U8R9fybsML99Ohj2DlZjk2e+rplN0TLcAoL74b5CW3c3bpA0CPmTU9Z2N/UERDlhTICDgnFj/bBxrnQ02YyE7yO5eg6U1I5hjYMBmpBYhqAIjr2fJlbzX76kUn8L0ZNtjKR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721910501; c=relaxed/simple; bh=SXY4BF5cH45vBfUcgibw+nKHrveyS2+pMaXmqyBH9Ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UbzGn48LDzq2FazwcEOT9vO2NxWurKIXRPy2jsJe1l9cRX8YQA8J+wfYR12E6PekGUV4lS5U7qwbXt8KuNj8jaR8mCOerxomVVdXH4FG8bFO8MqLg+4vjQDUBt5iriETBHs7BDVSF2HbOky/9t026kWeBvXsTGbseEGlfYh3ArM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.10.34]) by gateway (Coremail) with SMTP id _____8DxyOneRKJmV4cBAA--.5718S3; Thu, 25 Jul 2024 20:28:14 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.10.34]) by front1 (Coremail) with SMTP id qMiowMDxIuTcRKJmog8BAA--.7001S4; Thu, 25 Jul 2024 20:28:14 +0800 (CST) From: Bibo Mao To: Tianrui Zhao , Huacai Chen Cc: WANG Xuerui , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, x86@kernel.org Subject: [PATCH v3 2/2] LoongArch: KVM: Implement function kvm_arch_para_features Date: Thu, 25 Jul 2024 20:28:12 +0800 Message-Id: <20240725122812.3296140-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240725122812.3296140-1-maobibo@loongson.cn> References: <20240725122812.3296140-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qMiowMDxIuTcRKJmog8BAA--.7001S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxWw45tw4UWw13tFWkJryUCFX_yoW5GrWrpa yrArn8Gr4jkF1Sya98Jrs8Wr15Jrs7W3WxXF1jka4rAF47Crn8Ar1kta1qyF1DKa48W3WI gFWrJ3sak3WjvabCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUoxR6UUUUU Function kvm_arch_para_features() is to detect supported paravirt features, it can be used by device driver to detect and enable paravirt features, such as extioi irqchip driver can detect KVM_FEATURE_VIRT_EXTIOI and do some optimization. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/kvm_para.h | 10 ++++++++++ arch/loongarch/kernel/paravirt.c | 22 +++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/include/asm/kvm_para.h b/arch/loongarch/include/asm/kvm_para.h index 9814d56b8d0e..327f331d5237 100644 --- a/arch/loongarch/include/asm/kvm_para.h +++ b/arch/loongarch/include/asm/kvm_para.h @@ -155,10 +155,20 @@ static __always_inline long kvm_hypercall5(u64 fid, return ret; } +#ifdef CONFIG_PARAVIRT +bool kvm_para_available(void); +unsigned int kvm_arch_para_features(void); +#else +static inline bool kvm_para_available(void) +{ + return false; +} + static inline unsigned int kvm_arch_para_features(void) { return 0; } +#endif static inline unsigned int kvm_arch_para_hints(void) { diff --git a/arch/loongarch/kernel/paravirt.c b/arch/loongarch/kernel/paravirt.c index 9c9b75b76f62..4e8bccf4d92a 100644 --- a/arch/loongarch/kernel/paravirt.c +++ b/arch/loongarch/kernel/paravirt.c @@ -151,11 +151,14 @@ static void pv_init_ipi(void) } #endif -static bool kvm_para_available(void) +bool kvm_para_available(void) { int config; static int hypervisor_type; + if (!cpu_has_hypervisor) + return false; + if (!hypervisor_type) { config = read_cpucfg(CPUCFG_KVM_SIG); if (!memcmp(&config, KVM_SIGNATURE, 4)) @@ -165,16 +168,23 @@ static bool kvm_para_available(void) return hypervisor_type == HYPERVISOR_KVM; } +unsigned int kvm_arch_para_features(void) +{ + static int feature; + + if (!feature) + feature = read_cpucfg(CPUCFG_KVM_FEATURE); + return feature; +} + int __init pv_ipi_init(void) { int feature; - if (!cpu_has_hypervisor) - return 0; if (!kvm_para_available()) return 0; - feature = read_cpucfg(CPUCFG_KVM_FEATURE); + feature = kvm_arch_para_features(); if (!(feature & KVM_FEATURE_IPI)) return 0; @@ -260,12 +270,10 @@ int __init pv_time_init(void) { int r, feature; - if (!cpu_has_hypervisor) - return 0; if (!kvm_para_available()) return 0; - feature = read_cpucfg(CPUCFG_KVM_FEATURE); + feature = kvm_arch_para_features(); if (!(feature & KVM_FEATURE_STEAL_TIME)) return 0;