Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2554708lqz; Wed, 3 Apr 2024 01:08:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/IwxOH7aE1EhF9RPBV8ZspZwb/jcxDQkluKXMxw2/8tY0NA63awvlrXtyTzbziRKJP3NV7ZfFxJb0n9an1pr4kQpfRL6S1sNKwXrgcg== X-Google-Smtp-Source: AGHT+IFGPyXUce/BlHWI1kz6kmuAV4etEPR9U+xs518kSScJQCWWQV5lC56DOIRL30BSlqgbsPXr X-Received: by 2002:a17:906:37db:b0:a51:7658:2f0e with SMTP id o27-20020a17090637db00b00a5176582f0emr16712ejc.0.1712131721679; Wed, 03 Apr 2024 01:08:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712131721; cv=pass; d=google.com; s=arc-20160816; b=xsoKOFl9/gm7S7961izTmgYxtlJd7lhQy8oFuM1yFDZQW60bQ80BWC1W2sfl4VDDDk 9DRTrCqLijiVm24ChrjBYgbDm+l48MF+eMt9lOd3DJPQqB4zAFkuWsXOmKoFAxmxki9r yrMU/dDX+CDWQA+SGEtahUfURCrK4q3jRgJJGqj5bBSfrA5vbIGZRzCS2S0Wxotf9jiU T/vselioQlhgcasj/Ks3hFKwcwUEZE7im+mgpo6Bp4ZZOepqF9NJV3rhQioVHR9yJJIF Wl7xnQYJ3z/aIY7N+83DYLAga5IB2FkE3pzG1m/yiacy4MlCUQngdUhJeSOwWIe1/PZo WFow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; fh=EfSfkMqm8bhmjlBnspCOsQn4LXga6kog0QaqhijtOO4=; b=XsVK74QuDFBsPDyq7YoRI1jiks30EINvHnEse06cx1ADdu8sVDLOOVfXcC+Ige7Xq5 1CDBVx465CbfgYlf8YtdfuT386hJ13oth8OT6Ow0zQ2Cku+9a9YiU4UOsjfjUByxAsQZ vIetPb0eV1ilOhSP5ux46jORNFxEbBQXQ67lhETfZxt/312Xk+dgxTE5MVlKLPC2dDnh SP3k0xA/+6ESXqO8tJdBix1FB0o1yojlBHb5+juAoljJhWuOl4BqSfk7L0a4esLe5ouK pmZ2ful6/gONJBkeemrDKChvw8f5YXN+OyQSWQ/qKNbu21tgXS1FaLKWEX1LIf4KB3t+ RmwA==; 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=wZrRzEN4; 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-129251-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129251-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kb16-20020a1709070f9000b00a4df4220e77si6214366ejc.680.2024.04.03.01.08.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:08:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129251-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wZrRzEN4; 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-129251-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129251-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3F69D1F24EAE for ; Wed, 3 Apr 2024 08:08:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20AD98527B; Wed, 3 Apr 2024 08:05:39 +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="wZrRzEN4" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 B73FB83CC9 for ; Wed, 3 Apr 2024 08:05:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131538; cv=none; b=hyp3KseAZg8627p23K44TrkERmTUEmUqepdSNTOT69NQMFy5BwaeYhuEolE4bnjXKkFtw3HRSeTDv3c9wxfdqKlJcBDtwP4VNh3QpA6o6pQQ930Uy9h3bF7lKJ40I+Om+NcfGGtRWhKxVq/EO8tM1HedgeG4uvCo86uVsf1rsFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131538; c=relaxed/simple; bh=HvWaHaPle0cX5HGWWdRxWlP3z/kNux1E5mFj4+zTNsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c82xTAoo8nz4cxFe+/yymSj6jAeYsu+feh+y5GkU+nyU7WEecKmWtGUMhXoJXwIKbMiD4/E0ynlBZtpuv5xkO+0Fcbnt+DwQxUTZFTEpmP1brv9sagZAxh5aKcbR0g6aedGgkpc3RBN5v0I1qZkiIwMnzq65mfdigFx26zA24Cs= 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=wZrRzEN4; arc=none smtp.client-ip=209.85.214.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-pl1-f182.google.com with SMTP id d9443c01a7336-1e0d8403257so47314505ad.1 for ; Wed, 03 Apr 2024 01:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712131535; x=1712736335; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=wZrRzEN4mvK+xE6qW9yhoyBS7dtZadBB/pH+gn+EpBESynBYMsudJxE6XM0vBjKRB3 RJE2txVaYQacAX6JAGkvULmXR0NcL819Xptbg8nrZXvowUAR8TPXvWHN5KUGnHWWtr9K 1Bp9h+SV/BT/p/pG9NVf8U16filPqgWS0Dpbvu4tRDxo0V4ImkkQLfUeTcb4aL089Q/H NIBJ4Kyb2PTq1CrDOKRlieh++SM4v3yORgLpb9XDl6lbqgdGny+kzKveh7MyhdOlXXJz 7TbM01q2FeI2uYA75bD7BsLrb89HNKN5hqYrKUXePkvUwFdhdVs87jmO85njLvDL6Phi RuDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712131535; x=1712736335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=U8CNg4T3iVxIozREjIyN40fmsUxu2YwL67gd+TCPxgH484hY3C2FpNL8ory+8upDiE 4LlawWGzgCr+rcKNySVoDtRUKjAHhPn8sS3QG9wSIx4tK/11qBpLyHnK6kzEekLsk3zT fmsuyUqgJdaWXjSlsYHg/Gs1DsMWdy2OxIr7tejIQX05Y4dz9pbOjtK0p/O1hCXbbtw8 Sa46X7MFoyZHFlSAzlo7/LM6GrrXgNb6AbrEFxK9NlWfTV33DwRQ7xqShZxfSTF1gbfk 21xs+i+UKLGP9zcPLL4Bzk0bOCQPjXAuQBk0UWAcK5/aOMd3/yZnD7Muv9wqI76Rzob7 zzbw== X-Gm-Message-State: AOJu0Yws+0Dxbx0f+hWgK4f2VCYnqAnOJTYEZD1TJPzakiGNBoR91vTH tuAaEmb2VhpDHdFCeo/sx3dsalH5rljqM7rB6uEAlGCKOprlXfFTVa/fcylQsBaBk/+z2/vLcIt R X-Received: by 2002:a17:902:7881:b0:1e0:cd01:9fd with SMTP id q1-20020a170902788100b001e0cd0109fdmr11915195pll.26.1712131535324; Wed, 03 Apr 2024 01:05:35 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c12-20020a170902d48c00b001e0b5d49fc7sm12557229plg.161.2024.04.03.01.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:05:34 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Andrew Jones , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org Subject: [PATCH v5 11/22] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Wed, 3 Apr 2024 01:04:40 -0700 Message-Id: <20240403080452.1007601-12-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403080452.1007601-1-atishp@rivosinc.com> References: <20240403080452.1007601-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, we return a linux error code if creating a perf event failed in kvm. That shouldn't be necessary as guest can continue to operate without perf profiling or profiling with firmware counters. Return appropriate SBI error code to indicate that PMU configuration failed. An error message in kvm already describes the reason for failure. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 14 +++++++++----- arch/riscv/kvm/vcpu_sbi_pmu.c | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index b5159ce4592d..2d9929bbc2c8 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -229,8 +229,9 @@ static int kvm_pmu_validate_counter_mask(struct kvm_pmu *kvpmu, unsigned long ct return 0; } -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, - unsigned long flags, unsigned long eidx, unsigned long evtdata) +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, + unsigned long flags, unsigned long eidx, + unsigned long evtdata) { struct perf_event *event; @@ -454,7 +455,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata) { - int ctr_idx, ret, sbiret = 0; + int ctr_idx, sbiret = 0; + long ret; bool is_fevent; unsigned long event_code; u32 etype = kvm_pmu_get_perf_event_type(eidx); @@ -513,8 +515,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba kvpmu->fw_event[event_code].started = true; } else { ret = kvm_pmu_create_perf_event(pmc, &attr, flags, eidx, evtdata); - if (ret) - return ret; + if (ret) { + sbiret = SBI_ERR_NOT_SUPPORTED; + goto out; + } } set_bit(ctr_idx, kvpmu->pmc_in_use); diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index 7eca72df2cbd..e1633606c98b 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -42,9 +42,9 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, #endif /* * This can fail if perf core framework fails to create an event. - * Forward the error to userspace because it's an error which - * happened within the host kernel. The other option would be - * to convert to an SBI error and forward to the guest. + * No need to forward the error to userspace and exit the guest. + * The operation can continue without profiling. Forward the + * appropriate SBI error to the guest. */ ret = kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, temp, retdata); -- 2.34.1