Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp3978152ima; Tue, 23 Oct 2018 14:41:02 -0700 (PDT) X-Google-Smtp-Source: AJdET5esm1lI8ov1elhKE5CC1zFZC9qp0cv4t3MYHP7RNKNI1NgF+388UsZIujUVb5kVPSZzt3UB X-Received: by 2002:a63:1157:: with SMTP id 23mr659098pgr.245.1540330862746; Tue, 23 Oct 2018 14:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540330862; cv=none; d=google.com; s=arc-20160816; b=Sfqs7nV0GhBlHUK6vrXHD7Af+OawO1wAe8P/SQooozrCNubK+JLUVge8RbYMC0p7v/ ib8KiZdlPXzxuYbEZenzG5f/dE8izcoxAWg50znYzolHdVChy5pHG8TrFr3GeJ+xCmuv QjYeBG5fj+N/6gjLxdR5+Jsxd23s8axbFyvqVBSFvReMXMnJqF39h2kJ3SdOSzHk227d aXfLZuFOwe/VFCCZdQtNTR+rrz4K6lPGLQmSxC+4RjMStrWFvxxyWDWBMn9nz5ywj/YX xRApHJqHRRvH4DRXJzm5X/dF3yIClJsruwD1vmq5uPcuVVaiu9VppvXBkywksbRJHexd xlAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=jHQEGkfVrdoqqKizVltY2b1RQfcOPbDBd6kYMZWyPlM=; b=DVP3VGmadDKanO97MmIOMjNsfihLOV3UUDd88/nhCLMgndvewTe3I/l78oTNmZpYrI Hyr1dckXQ1xQtlpsZPuSJrwUkzSR5PjE7WdhNRXs1IUbDC21hrHMPOX+tOpUcv4ZYCvn yUY9NrL0j0W4LORz4mT0zXoDpLhG9hYdlsrXudykRZrz1U5NnKN60zHIunhB08Sf9t6r wj4c8oOw+v2ZAeDCHZgs3x57J5ovhgcgxFsm+6K8Tp4atgbV+z+A3bkASj/GDtMNvwr/ t+Zt5P4TNwqKqCkd9lajggGK/2qfDfxTHbIrbWGHR+UfC68wOJH0aEbSvHkWawHj5AkM RHBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Dd49pQ0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g35-v6si2407916pgm.514.2018.10.23.14.40.47; Tue, 23 Oct 2018 14:41:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Dd49pQ0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728758AbeJXGFl (ORCPT + 99 others); Wed, 24 Oct 2018 02:05:41 -0400 Received: from rcdn-iport-4.cisco.com ([173.37.86.75]:5643 "EHLO rcdn-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbeJXGFl (ORCPT ); Wed, 24 Oct 2018 02:05:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2002; q=dns/txt; s=iport; t=1540330828; x=1541540428; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=58B8RRPYBCJ60ow6croL5YgH1PwEoU/3Hr7hsBhUVNg=; b=Dd49pQ0fNqBC9PAWtkqMzHaqewAroq036z74dzW/P9lhVpwxPHxJAQoK QpNjewg28ag5WJZEg58mgURF4sKw4JWC1xUAexrcomAFAM17074j0epb2 ZjBYt5fuIbcGTllNp+k0BXC0xhF55PXIFvMOR9zSfIHiWQYePfQEmSlPF w=; X-IronPort-AV: E=Sophos;i="5.54,417,1534809600"; d="scan'208";a="470623750" Received: from alln-core-7.cisco.com ([173.36.13.140]) by rcdn-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2018 21:40:27 +0000 Received: from [10.154.208.140] ([10.154.208.140]) by alln-core-7.cisco.com (8.15.2/8.15.2) with ESMTP id w9NLeAf5000968; Tue, 23 Oct 2018 21:40:10 GMT Subject: Re: [PATCH v2] kernel/signal: Signal-based pre-coredump notification To: Oleg Nesterov Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Peter Zijlstra , Arnd Bergmann , "Eric W. Biederman" , Khalid Aziz , Kate Stewart , Helge Deller , Greg Kroah-Hartman , Al Viro , Andrew Morton , Christian Brauner , Catalin Marinas , Will Deacon , Dave Martin , Mauro Carvalho Chehab , Michal Hocko , Rik van Riel , "Kirill A. Shutemov" , Roman Gushchin , Marcos Paulo de Souza , Dominik Brodowski , Cyrill Gorcunov , Yang Shi , Jann Horn , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, "Victor Kamensky (kamensky)" , xe-linux-external@cisco.com, Stefan Strogin , Enke Chen References: <458c04d8-d189-4a26-729a-bb1d1d751534@cisco.com> <20181023092348.GA14340@redhat.com> <1e68a3ce-32cd-b058-3d1d-36455ceca848@cisco.com> From: Enke Chen Message-ID: Date: Tue, 23 Oct 2018 14:40:10 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1e68a3ce-32cd-b058-3d1d-36455ceca848@cisco.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.154.208.140, [10.154.208.140] X-Outbound-Node: alln-core-7.cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Oleg: On 10/23/18 12:43 PM, Enke Chen wrote: >> >>> --- a/fs/coredump.c >>> +++ b/fs/coredump.c >>> @@ -546,6 +546,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) >>> struct cred *cred; >>> int retval = 0; >>> int ispipe; >>> + bool notify; >>> struct files_struct *displaced; >>> /* require nonrelative corefile path and be extra careful */ >>> bool need_suid_safe = false; >>> @@ -590,6 +591,15 @@ void do_coredump(const kernel_siginfo_t *siginfo) >>> if (retval < 0) >>> goto fail_creds; >>> >>> + /* >>> + * Send the pre-coredump signal to the parent if requested. >>> + */ >>> + read_lock(&tasklist_lock); >>> + notify = do_notify_parent_predump(current); >>> + read_unlock(&tasklist_lock); >>> + if (notify) >>> + cond_resched(); >> >> Hmm. I do not understand why do we need cond_resched(). And even if we need it, >> why we can't call it unconditionally? > > Remember the goal is to allow the parent (e.g., a process manager) to take early > action. The "yield" before doing coredump will help. > > The yield is made conditional because the notification is conditional. > Is that ok? Given this is in do_coredump(), it is ok to make it unconditional for simplicity. >> >>> +bool do_notify_parent_predump(struct task_struct *tsk) >>> +{ >>> + struct sighand_struct *sighand; >>> + struct kernel_siginfo info; >>> + struct task_struct *parent; >>> + unsigned long flags; >>> + pid_t pid; >>> + int sig; >>> + >>> + parent = tsk->parent; >>> + sighand = parent->sighand; >>> + pid = task_tgid_vnr(tsk); >>> + >>> + spin_lock_irqsave(&sighand->siglock, flags); >>> + sig = parent->signal->predump_signal; >>> + if (!valid_predump_signal(sig)) { >>> + spin_unlock_irqrestore(&sighand->siglock, flags); >>> + return false; >>> + } >> >> Why do we need to check parent->signal->predump_signal under ->siglock? >> This complicates the code for no reason, afaics. Will simplify. Thanks. -- Enke