From patchwork Wed Aug 29 23:42:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Shier X-Patchwork-Id: 10581081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C98FD1390 for ; Wed, 29 Aug 2018 23:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFA85285B0 for ; Wed, 29 Aug 2018 23:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A040328675; Wed, 29 Aug 2018 23:43:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 476F9285B0 for ; Wed, 29 Aug 2018 23:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbeH3DmN (ORCPT ); Wed, 29 Aug 2018 23:42:13 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:34567 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727149AbeH3DmM (ORCPT ); Wed, 29 Aug 2018 23:42:12 -0400 Received: by mail-pg1-f201.google.com with SMTP id w23-v6so4013391pgv.1 for ; Wed, 29 Aug 2018 16:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=mwIn1CkFpO4VKzmymzcb20ODfnRuyRZkT1UK1cZBpis=; b=PCppYTUANchvxBKNzoyxTE1r0cKfhddTpxIXfnKHaWixK48Fw+EBxTld4A0WY+Gfyh 3gIgS8XgJ/Peio8VcLeW1tei/wO2Lh0qpK52jcFbTEOS8OwwrGF4WEURfsDcmuFBAj0W sT1ijWhq9eq03aG7VpHWZHCXnredOsRgH7K8TCQc6RIn9H9ZfLDzWLl2bDqdiFDW9YLg 9hRVgbIJYTjx3WhsPlFV3OsaGmCDftrEKLHqsU/Aqvwobf8tcLUUPaHlbBH+UBKHkW0+ TGWoMv4IIFzWK+cHoNiB70OZurKaz+iFyExZg+n4Xgf9p1MK09Lii0iVITXM/PWAhgII kMnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=mwIn1CkFpO4VKzmymzcb20ODfnRuyRZkT1UK1cZBpis=; b=b/D8+1tW6FVz98SLAMLWe/hRc136QsO1AHWyzPCynGO9gGdCiK1X3j7W3gFjZ9p+wk EoKI9O17zwLubwQyXOSK+Hrq7eXn1Sj46E6Ic6Tl8hWAwlwCPzbZoXxOeuRCSRpe3Kzb /SOiE8cse5sfpyeUEoD3Ay3QCzoBra8YSzRMkNa2itdrVBT8kgwRetMTmafEuzDKDlXU HQmyTlezV7Eww/m/StBRAfI2WB9Hv0w++bVUvUHSX3OnN83PUStLiSn52tPy+TmMLRX2 noCYjIfyTJBLJEXMTErHK3YvT0iqof69N6W/+b0uWszUPuvuvEYUb07zDBQPJ5uyQJ0F zdFw== X-Gm-Message-State: APzg51BUeQaKDsTW8ZU5UNBponpNbG+qjwLAV3Gtb884QqRElQT3/HDW UPBABxYbs3w66hU3pCYyNXFGn7B8Z6XpoVkkUICXaKVApvPDRc/t5ETarN9UDUHkiHH6WLqSJ5U pMvombv2IPq1GwByq1mrdvwPLpUkLaPgUH7+XVNF8gOUNnZ0D9paVZRLFDw== X-Google-Smtp-Source: ANB0VdbzMULQ+w0V5snub5UxttXUCCC64bPvko6hAiTTGkevvI9m0XDHoS72hFFza+kJ0Sn06MtaSnfL5tg= X-Received: by 2002:a63:d704:: with SMTP id d4-v6mr2166170pgg.96.1535586174717; Wed, 29 Aug 2018 16:42:54 -0700 (PDT) Date: Wed, 29 Aug 2018 16:42:39 -0700 Message-Id: <20180829234241.103002-1-pshier@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH 0/2] Propagate accurate MSR access failures to userspace From: Peter Shier To: kvm@vger.kernel.org Cc: jmattson@google.com, Peter Shier Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP KVM_GET/SET_MSRS ioctls do not enable userspace clients to differentiate between ioctl execution errors (e.g. bad pointer, memory allocation failure) and MSR access errors (e.g. bad MSR parameter, unknown MSR). This series repurposes kvm_msrs.pad to return the error from the first failed msr access. It enables callers to use a sequence such as: struct kvm_msrs msrs; ... init msrs ... r = ioctl(vcpu_fd, KVM_GET_MSRS, &msrs); if (r < 0) { check errno for ioctl execution error } else if (r < msrs.nmsrs) { if r > 0 reading msrs.entries[0]..msrs.entries[r-1] succeeded reading msrs.entries[r] failed msrs.errno has the reason } The second patch changes code that handles ranges of MSRs to return -ENOENT when it encounters an unknown MSR. Prior to this it was not possible for userspace to differentiate between unknown MSRs and other MSR access errors. The patches do not change any existing API contracts or guest-visible exceptions. Peter Shier (2): kvm: x86: propagate KVM_GET/SET_MSRS failures to userspace kvm: x86: differentiate unrecognized MSRs from errors Documentation/virtual/kvm/api.txt | 12 ++++++++--- arch/x86/include/uapi/asm/kvm.h | 2 +- arch/x86/kvm/hyperv.c | 16 +++++++-------- arch/x86/kvm/lapic.c | 2 +- arch/x86/kvm/mtrr.c | 10 ++++++--- arch/x86/kvm/pmu_amd.c | 24 ++++++++++++---------- arch/x86/kvm/pmu_intel.c | 5 +++-- arch/x86/kvm/vmx.c | 4 ++-- arch/x86/kvm/x86.c | 34 +++++++++++++++++++------------ 9 files changed, 65 insertions(+), 44 deletions(-)