From nobody Fri Dec 26 01:30:08 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 2CC46145332 for ; Fri, 19 Apr 2024 23:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570489; cv=none; b=HTATqmJzAvXVWotV+Vx3Q/I5e0MgHZNtsHlixHkogqjdYoW5bE81u7aw6dle5g06SBzSqYPR/GiSLx9pnv3Niq+JmC1WfeAwce8xL9NSfR0Jy37ujq5Z3030PrXJhC7pt5LGXpu23gPahWd1ErhD/kAJC6c8vlsjyjZp68v1Kjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570489; c=relaxed/simple; bh=HvWaHaPle0cX5HGWWdRxWlP3z/kNux1E5mFj4+zTNsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SsT/824y5crQkSyPKG1yctf7deuuYce6Ifq+0xJEYsfiPcUnG4mTJXsWOZwR7xhXQWNgBcqQufIbjoX1W7wSHhdHQKy5Dp+ourD9YDup0W30sioNMMPYx1L7MjQwgfxcsQ4FtoVyS8FVnz3uIGyJdicgEkYFnuNlFatSYZVlUYc= 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=cJCvo89h; arc=none smtp.client-ip=209.85.214.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 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="cJCvo89h" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e2c725e234so28948435ad.1 for ; Fri, 19 Apr 2024 16:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713570487; x=1714175287; 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=cJCvo89hEyk6GbDOFp5RLHQw58DSuFQTp/0zQcToUPJZwu6P4YuYSRHd6m7PrXskH/ uK6p9UObHFVq0JLhjfUssmmjce9NJdOUqNwmznYXhMA+uezU9ZYfDUqrtx10pwD0CoUc tvX3UdzmiSvnYekze2riw+I92dqtj7+1ilXhP1mw6kEXOvz0aWC653mopKLRWujQ4P5d GqUnbWwVtDvmJSoCteG9v4Ai05+kerneZlKqbbPmbwfW9YThsbXi7JQ1J4Mdky+MPSLQ EZGOqJKYcP9KoLsNC4vI+nO7m4908CcN+HiQTZzsRK/88GW7RMRcXBX5FNbycRUinims q47Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713570487; x=1714175287; 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=NvpNUa8jhkZHvV3NV07JxuPF0eIxdTlf0o9/GmPXxRbnJLBC0AlmK0vALy9TS0Sm2x OE42JXuKRRNXZYylB9PPsfC48MaDxS4a3B5cS41sl3MfMVPVF0tjnbbQTbAZ9tHhizyb YorTWmq/1myZSrzVjdtxgsG9MBhfpdHMzhxwTfbmCfOmy9/klNCUfhCDqpfS3/A+9XQ/ v11mmRZ6ByGUbmvaNnMh9dg0MqUwS23sJJDnU+QoGN1LAVuclytJJDrsh1Mjx1HLDpjl VnZLTeCaYMxRP7thDnHFw+6VwN0zCzdAIQod7mvJL8RYCASi2ErcLCY9vYSHmsejJssL attw== X-Gm-Message-State: AOJu0YyK51qXPEt68eJRPXNBYUfSoLdlb45s/Yhsjz0Az/EeqOAgZi+G Xc/5ZdiI5FBd5fzfGgVM7tZNl6zH6ocjTB++ZNJan4E0TGQOSW7AV++oegzZNDK7rvzhEv32Ntm S X-Google-Smtp-Source: AGHT+IHqmOgwdzykdLgMc2WJ6EaM228nMawdh3bGDIhVF9FxVvuRHHcpcsw9cNr0lYOB2vXlkqEb3Q== X-Received: by 2002:a17:902:d481:b0:1e7:d3e3:a927 with SMTP id c1-20020a170902d48100b001e7d3e3a927mr5602995plg.31.1713570486735; Fri, 19 Apr 2024 16:48:06 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w17-20020a170902d11100b001e42f215f33sm3924017plw.85.2024.04.19.16.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:48:06 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , Andrew Jones , samuel.holland@sifive.com, 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, Will Deacon , x86@kernel.org Subject: [PATCH v8 12/24] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Sat, 20 Apr 2024 08:17:28 -0700 Message-Id: <20240420151741.962500-13-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240420151741.962500-1-atishp@rivosinc.com> References: <20240420151741.962500-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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; } =20 -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_even= t_attr *attr, - unsigned long flags, unsigned long eidx, unsigned long evtdata) +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_eve= nt_attr *attr, + unsigned long flags, unsigned long eidx, + unsigned long evtdata) { struct perf_event *event; =20 @@ -454,7 +455,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *v= cpu, unsigned long ctr_ba unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata) { - int ctr_idx, ret, sbiret =3D 0; + int ctr_idx, sbiret =3D 0; + long ret; bool is_fevent; unsigned long event_code; u32 etype =3D 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 =3D true; } else { ret =3D kvm_pmu_create_perf_event(pmc, &attr, flags, eidx, evtdata); - if (ret) - return ret; + if (ret) { + sbiret =3D SBI_ERR_NOT_SUPPORTED; + goto out; + } } =20 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 =3D kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, temp, retdata); --=20 2.34.1