From patchwork Wed Jun 9 17:23:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Rusin X-Patchwork-Id: 12310813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B3A2C48BCD for ; Wed, 9 Jun 2021 17:23:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17742613C8 for ; Wed, 9 Jun 2021 17:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17742613C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=vmware.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D10A46E9E3; Wed, 9 Jun 2021 17:23:18 +0000 (UTC) Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by gabe.freedesktop.org (Postfix) with ESMTPS id F03A26E9B6 for ; Wed, 9 Jun 2021 17:23:13 +0000 (UTC) Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 9 Jun 2021 10:23:10 -0700 Received: from vertex.localdomain (unknown [10.21.244.178]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 04A0B2024E; Wed, 9 Jun 2021 10:23:12 -0700 (PDT) From: Zack Rusin To: Subject: [PATCH 7/9] drm/vmwgfx: Refactor vmw_mksstat_remove_ioctl to expect pgid match with vmw_mksstat_add_ioctl to authorise removal. Date: Wed, 9 Jun 2021 13:23:05 -0400 Message-ID: <20210609172307.131929-8-zackr@vmware.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210609172307.131929-1-zackr@vmware.com> References: <20210609172307.131929-1-zackr@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: zackr@vmware.com does not designate permitted sender hosts) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Krastev Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Martin Krastev Original vmw_mksstat_remove_ioctl expected pid to match the corresponding vmw_mksstat_add_ioctl. That made impossible en-masse removals by one pid, which is a valid use case, so pid match was discarded. Current change enforces a broader pgid match as a form of protection from arbitrary processes interrupting an ongoing mks-guest-stats. Reviewed-by: Zack Rusin Signed-off-by: Martin Krastev Signed-off-by: Zack Rusin --- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c index 12df4c634075..74a3f09ad664 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c @@ -1111,7 +1111,7 @@ int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data, hypervisor_ppn_add((PPN64)page_to_pfn(page)); dev_priv->mksstat_user_pages[slot] = page; - atomic_set(&dev_priv->mksstat_user_pids[slot], current->pid); + atomic_set(&dev_priv->mksstat_user_pids[slot], task_pgrp_vnr(current)); arg->id = slot; @@ -1158,37 +1158,31 @@ int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data, struct vmw_private *const dev_priv = vmw_priv(dev); const size_t slot = arg->id; - pid_t pid0; + pid_t pgid, pid; if (slot >= ARRAY_SIZE(dev_priv->mksstat_user_pids)) return -EINVAL; DRM_DEV_INFO(dev->dev, "pid=%d arg.id=%lu\n", current->pid, slot); - pid0 = atomic_read(&dev_priv->mksstat_user_pids[slot]); + pgid = task_pgrp_vnr(current); + pid = atomic_cmpxchg(&dev_priv->mksstat_user_pids[slot], pgid, MKSSTAT_PID_RESERVED); - if (!pid0) + if (!pid) return 0; - if (pid0 != MKSSTAT_PID_RESERVED) { - const pid_t pid1 = atomic_cmpxchg(&dev_priv->mksstat_user_pids[slot], pid0, MKSSTAT_PID_RESERVED); + if (pid == pgid) { + struct page *const page = dev_priv->mksstat_user_pages[slot]; - if (!pid1) - return 0; - - if (pid1 == pid0) { - struct page *const page = dev_priv->mksstat_user_pages[slot]; + BUG_ON(!page); - BUG_ON(!page); - - dev_priv->mksstat_user_pages[slot] = NULL; - atomic_set(&dev_priv->mksstat_user_pids[slot], 0); + dev_priv->mksstat_user_pages[slot] = NULL; + atomic_set(&dev_priv->mksstat_user_pids[slot], 0); - hypervisor_ppn_remove((PPN64)page_to_pfn(page)); + hypervisor_ppn_remove((PPN64)page_to_pfn(page)); - vmw_mksstat_cleanup_descriptor(page); - return 0; - } + vmw_mksstat_cleanup_descriptor(page); + return 0; } return -EAGAIN;