From patchwork Mon Mar 6 16:31:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenghua Yu X-Patchwork-Id: 64976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1956252wrd; Mon, 6 Mar 2023 09:04:20 -0800 (PST) X-Google-Smtp-Source: AK7set9r7LjaYpwsHCPdTUUqlaYUi+pw6Z6ySJAV4/Rnk60sOv6K9JPuMq5pngvVWxponyGpSIET X-Received: by 2002:a17:906:175b:b0:8b1:3483:e3d5 with SMTP id d27-20020a170906175b00b008b13483e3d5mr10919574eje.48.1678122260594; Mon, 06 Mar 2023 09:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678122260; cv=none; d=google.com; s=arc-20160816; b=Zq/yBIlIukytR/41sJIFC9eLSTC0IC3SeIcM6Rk7JiiSGju2R5L77MRZ+hbEstw6i7 pZqrE0zkkAxUFideUkA42H1ZJeO8yKguPAD5dB8xqUmyxZOOqoqaqElaHYfM9Uuni5kb TqnZBmeierFs2/ubvDqvvX1Iy3FsgZBV6ECAoocsTeUDAARLJwbWyTQO5tZmBskYo9Hz CUahJ64h0FXUA3C2wcQzK5clDdkHNvfk3+hB67tX3hfxkDmrsmIJBECUCbIj88vnuq2N vANglfMhVHMcWqKgASTEiQ553PQKJ3x8DO3BUrx5QNSj46vhfy8L7R4UBvguo83dtBkd 29MA== 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=1dC8hvskdDC2BAKcbjKrgHQPlwDF6c9TGmFomiP2VnM=; b=RFllRufz0SuGujz2pnhMtmts3lNW+o+l+57/A8LyYm7AfHSjxPCoaM6BIJKkcAb+nV zFha8Qxku9T/l69d1gD3HvbC6E5dx57HJBsbsoi8Ga2kjEnu44Fa9PQM8+tFYssZE7+H rpJ6NYmlcdC5++CmyxMEMFAnCbDzt6jfZyAPCrsL6BsAkwMEyy8zb6VrNubhQpbdr+F7 ANzR4OArveKWYXG+dDPE9uJcO7DrNvBsa0300yx4PUmB3pdXoGePBCN0/BeuOoHWv8Ev GTGbvnOY8Aiwl7/oT4te1koZeZ60d03wlIz/IKt+UScgvVgNhrvKf8N7LenJ1igQiZ3C qYXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OfDxNkdP; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 3-20020a170906328300b008e21a3323d0si10432598ejw.673.2023.03.06.09.03.56; Mon, 06 Mar 2023 09:04:20 -0800 (PST) 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=OfDxNkdP; 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 S230299AbjCFQqi (ORCPT + 99 others); Mon, 6 Mar 2023 11:46:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbjCFQoq (ORCPT ); Mon, 6 Mar 2023 11:44:46 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344733E0B9; Mon, 6 Mar 2023 08:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678121052; x=1709657052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7mSzveSNY4kQknpqyVT1O/9858OwAEHn5l3ARji8dAY=; b=OfDxNkdPUD3viI0Z/KfUkMLfwX4gGiKs/rRMhQP2WeRr/A+U/LaYKjpg 5GicFpOik0CHwkgfDhgBEsszrDyu/HsVcqy4aaM02fSTLUIBYDheydy36 Obmkwwv7udFJ3mgwzqMRB3oljDxHy74k6R5JpVKJuhnUxv4fD0GKQwp/v d3lv/J3pR1vRRdv0Hu+Z2iCKFJmaaOHRrC1EjNEuTHSNZhzG+w71cwURy B50UjetpjF4/XWIzkcw0trKbDx+fvfKfYbzsjwrDYWAdMbBm9mELGVFEP mA7tdN9DkkykRLcyp3JQXD6/sthGrGa4c0TZcbxf1x4qM6NRllHUNCsbU Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="398181189" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="398181189" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 08:31:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="669504562" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="669504562" Received: from fyu1.sc.intel.com ([172.25.103.126]) by orsmga007.jf.intel.com with ESMTP; 06 Mar 2023 08:31:59 -0800 From: Fenghua Yu To: "Vinod Koul" , "Dave Jiang" Cc: dmaengine@vger.kernel.org, "linux-kernel" , Tony Zhu , Fenghua Yu Subject: [PATCH v2 15/16] dmaengine: idxd: add pid to exported sysfs attribute for opened file Date: Mon, 6 Mar 2023 08:31:37 -0800 Message-Id: <20230306163138.587484-16-fenghua.yu@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230306163138.587484-1-fenghua.yu@intel.com> References: <20230306163138.587484-1-fenghua.yu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759638727423970186?= X-GMAIL-MSGID: =?utf-8?q?1759638727423970186?= 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 9fc6565bf807..e124f0628f1c 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -47,6 +47,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); @@ -76,9 +77,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 }; @@ -236,6 +246,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);