Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1309761rwl; Fri, 7 Apr 2023 13:34:13 -0700 (PDT) X-Google-Smtp-Source: AKy350brMMYn0ft6S26FuEMM3KHGAUrUZSripM7VIuq/pCe/nHITJTcO7qQT8gMo0MhAjDh+I0zn X-Received: by 2002:aa7:d741:0:b0:4fc:9c79:86bc with SMTP id a1-20020aa7d741000000b004fc9c7986bcmr3707918eds.42.1680899652931; Fri, 07 Apr 2023 13:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680899652; cv=none; d=google.com; s=arc-20160816; b=OwjqsjT5oP+jO9FaaL0gvuSxFruJtOhNfm1Cn/CxOvdW010iubtj9r3Dlp8wSCxVAL n2ue5DeY0WIhBW+SRfYwYeuHlArPYGuSNFm9BYaFudvx+jDWpH183wRrRrg0NP7JjGJp POE21uE+BnpExd0CYwkbSkH6wOsDq9CPeF6W7/ZZi4EFdQAW+Qn/+hh5RQXIbmXnbe1z DnwiLXOho2+KD3hEoh7fTqehLeI1N1voxy1/M+l02OTkkiBIiIaX1rLsJfKTYvvCW9SF Cv557McU9DC3kefoYSAbE6mG28V0iV5+kUh0O+gHGDjb1H9TKeMtFfaGzPwO23D/MSRU tWKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N/pRVaR72OZDHuNEun5d2/jKE434Cs8rAGXW3PBswQ0=; b=G3aHQe5I56LrL0hfvp8DEKc/WjYSR1dx/pkNhNttTvhdIIEejy7FR7KBdfTQjtOct8 sPuDMzdSI7iKGu5C2BswRI8hNWZ/1H54Q5JIRZVLMSMz8ooa+8hEE1cRJEut5CHTkIiM bOtOyaCMvuC+4HVXdIalerQDxZeWHELKCLQexIhOdWjLtWxQBojKgS3eeQqzl/D7ZrZf muhuYWjhUT3LnIMmJ7Dl1yj9YFWqB/w3+KUxHdYRxG3IWrFsPAoyBjDMUzwmn2/kvb2N /AMOz2+t9a4FBxAcXORiBIUuQl/yynrBWQD8611N6Nyl+Y4ExU9MGXvpxaR5Dbj4xASy XVyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J25Uyzze; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j20-20020aa7ca54000000b005029d15aa77si564518edt.15.2023.04.07.13.33.48; Fri, 07 Apr 2023 13:34:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J25Uyzze; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbjDGUcW (ORCPT + 99 others); Fri, 7 Apr 2023 16:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231352AbjDGUbl (ORCPT ); Fri, 7 Apr 2023 16:31:41 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4246FCA2B; Fri, 7 Apr 2023 13:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680899494; x=1712435494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g5ilb4+0dWGScQreqTS5r5+hbNiJgbK8srbCtL8vqqw=; b=J25Uyzze8RcFgkB5OzXDLdNztfKIRIVMOgle01HIlERaJLrWooJXR2xU EtC7Q0NHFfCFGnt6MV+/E2k4cnsDi21xC/m1lMUmYiNGiFdudrBnUOcOz q894LQY95Hh98XkNuEAg+n4BaSznedfqHyahELKUOXVspfhBvU1S4cFGo bQug5LzAiEVlbR+LxNcxMzDvDRbKBi1/dRK2cLwjlpIEAUoDSEGR1pwu6 MOic4M7+28v9wVlmbnoX/GIeSsk38nG9cFVYTsV0LppdkQVmzGh26rNKG LZ1DgtD69kKP7rOo1vSwWOH6H/H3yC+LfcO7U6gMq4qwAdWGwoqAHpRQK A==; X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="408196882" X-IronPort-AV: E=Sophos;i="5.98,327,1673942400"; d="scan'208";a="408196882" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 13:31:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="681125906" X-IronPort-AV: E=Sophos;i="5.98,327,1673942400"; d="scan'208";a="681125906" Received: from fyu1.sc.intel.com ([172.25.103.126]) by orsmga007.jf.intel.com with ESMTP; 07 Apr 2023 13:31:28 -0700 From: Fenghua Yu To: "Vinod Koul" , "Dave Jiang" Cc: dmaengine@vger.kernel.org, "linux-kernel" , Tony Zhu , Fenghua Yu Subject: [PATCH v4 15/16] dmaengine: idxd: add pid to exported sysfs attribute for opened file Date: Fri, 7 Apr 2023 13:31:42 -0700 Message-Id: <20230407203143.2189681-16-fenghua.yu@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230407203143.2189681-1-fenghua.yu@intel.com> References: <20230407203143.2189681-1-fenghua.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Jiang Provide the pid of the application for the opened file. This allows the monitor daemon to easily correlate which app opened the file and easily kill the app by pid if that is desired action. Tested-by: Tony Zhu Signed-off-by: Dave Jiang Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu --- Documentation/ABI/stable/sysfs-driver-dma-idxd | 8 ++++++++ drivers/dma/idxd/cdev.c | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-driver-dma-idxd b/Documentation/ABI/stable/sysfs-driver-dma-idxd index 73ab86196a41..5d0df57f5298 100644 --- a/Documentation/ABI/stable/sysfs-driver-dma-idxd +++ b/Documentation/ABI/stable/sysfs-driver-dma-idxd @@ -335,3 +335,11 @@ Description: Show the number of Completion Record (CR) faults failures that this driver cannot fault in the address for the CR. Typically this is caused by a bad address programmed in the submitted descriptor or a malicious submitter is using bad CR address on purpose. + +What: /sys/bus/dsa/devices/wq./dsa\!wq./file/pid +Date: Sept 14, 2022 +KernelVersion: 6.4.0 +Contact: dmaengine@vger.kernel.org +Description: Show the process id of the application that opened the file. This is + helpful information for a monitor daemon that wants to kill the + application that opened the file. diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c index 2fb905f2545b..ecbf67c2ad2b 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -49,6 +49,7 @@ struct idxd_user_context { struct idxd_dev idxd_dev; u64 counters[COUNTER_MAX]; int id; + pid_t pid; }; static void idxd_cdev_evl_drain_pasid(struct idxd_wq *wq, u32 pasid); @@ -78,9 +79,18 @@ static ssize_t cr_fault_failures_show(struct device *dev, } static DEVICE_ATTR_RO(cr_fault_failures); +static ssize_t pid_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct idxd_user_context *ctx = dev_to_uctx(dev); + + return sysfs_emit(buf, "%u\n", ctx->pid); +} +static DEVICE_ATTR_RO(pid); + static struct attribute *cdev_file_attributes[] = { &dev_attr_cr_faults.attr, &dev_attr_cr_fault_failures.attr, + &dev_attr_pid.attr, NULL }; @@ -238,6 +248,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) ctx->wq = wq; filp->private_data = ctx; + ctx->pid = current->pid; if (device_user_pasid_enabled(idxd)) { sva = iommu_sva_bind_device(dev, current->mm); -- 2.37.1