Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2625669pxu; Mon, 7 Dec 2020 11:07:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyql83Brqwh+oUIoagXf9VDEX/1ZPp+/Uhg0BMUSiKSc3wHKAjVfwa6aHCqxptm+ub7Nde5 X-Received: by 2002:a50:a410:: with SMTP id u16mr21483826edb.274.1607368026782; Mon, 07 Dec 2020 11:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607368026; cv=none; d=google.com; s=arc-20160816; b=tLd/Yr4z5L3Y717+jwsbBwByI6UpkRJeeK7yJpnCR21ZMhRsIxvlIIYzYMrWJ+tDJD t0COB8M/d4PbJg2VgZ6Voaq12xfAE4/6nukjoRa7GQ7Icmw4ryDctAXTBShOJXFYz+80 84R91b3ihBRKaTPY5GGv5IzMoWkmOofkF9PWQJoZ9fvrMDMLlWNNWcfnp6/A9svkoR7C t+788UgXvGrYVwmKrAStHDJOzUL+rQPhsbWkZ51Kldhaxk013TWvImkcYwi54z5lV+R9 5hUaghT9zRqpieVztJFLLZqG46cWoELTliZAUISKfJKnVBzq0gidzReZFDmXjnFtIHpH tceA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=yjB17pjd2723LqhuIlVK0z7MCUqX+HkOOB14OY2CKoY=; b=OGycqnyQGgKESdWfT3RVwYfX226isvI5KFCqny7fDNifUn78isx/3Xv6nJyfaACBzx +sklovxgWmOBfGjbi/bJWTGiyEkYwEErHLJzyVSISV7RhV7VCC10r3ZMFPuNu9ayRz5B 1zf4SukBUuBcm+UOC2hfYBU3ZmqVFDwj1UcFFQ3dPj/+biORKrZXZWT5oyNhqM3BCMsf EhyJT+7fYFEJyvqBbMDRpMtSyGYxhDv2ZDgb5VSvt3gWXYBXfV/G4FvW37K5wGEeTEVh uqwgML4kYJbRqInok5zxB9MJ0T7QuL4PReS5RpAZxqeGcBQ3vBIhfy9bP9nWHs/6SrMQ D9VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YA6DazpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si6839923ejr.681.2020.12.07.11.06.43; Mon, 07 Dec 2020 11:07:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YA6DazpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgLGTEG (ORCPT + 99 others); Mon, 7 Dec 2020 14:04:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58289 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbgLGTEF (ORCPT ); Mon, 7 Dec 2020 14:04:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607367759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yjB17pjd2723LqhuIlVK0z7MCUqX+HkOOB14OY2CKoY=; b=YA6DazpRSo6Ux63JVMwcDmyaCT/prPUYQHf4mJdoRqljLSmJGgwVNPWJTpowBIsRlvuuvW aMl9pGNIBvWifFDUlBsT7tRfgnqEV8R4tU/YMKQ1vEWx1Fpiz8Souq0XVh8GVMoitS0Qvh PRbyngNdlVQ9Qu+ie5MOCAzg6aJEflc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-XNRdJasSOM2Qx4iI42Hb-w-1; Mon, 07 Dec 2020 14:02:35 -0500 X-MC-Unique: XNRdJasSOM2Qx4iI42Hb-w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BC4F80400B; Mon, 7 Dec 2020 19:02:32 +0000 (UTC) Received: from llong.remote.csb (ovpn-118-86.rdu2.redhat.com [10.10.118.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0024D60C05; Mon, 7 Dec 2020 19:02:25 +0000 (UTC) Subject: Re: [PATCH 2/3] rwsem: Implement down_read_interruptible To: David Laight , Peter Zijlstra Cc: "Eric W. Biederman" , "linux-kernel@vger.kernel.org" , Linus Torvalds , Ingo Molnar , Will Deacon , Jann Horn , Vasiliy Kulikov , Al Viro , Bernd Edlinger , Oleg Nesterov , Christopher Yeoh , Cyrill Gorcunov , Sargun Dhillon , Christian Brauner , Arnd Bergmann , Arnaldo Carvalho de Melo References: <87tut2bqik.fsf@x220.int.ebiederm.org> <87k0tybqfy.fsf@x220.int.ebiederm.org> <620f0908-c70a-9e54-e1b5-71d086b20756@redhat.com> <20201207090243.GE3040@hirez.programming.kicks-ass.net> <7be81903-14e3-7485-83e7-02e65e80e8c3@redhat.com> From: Waiman Long Organization: Red Hat Message-ID: Date: Mon, 7 Dec 2020 14:02:25 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/7/20 11:58 AM, David Laight wrote: > From: Waiman Long >> Sent: 07 December 2020 15:34 >> >> On 12/7/20 4:02 AM, Peter Zijlstra wrote: >>> On Thu, Dec 03, 2020 at 08:59:13PM -0500, Waiman Long wrote: >>>> On 12/3/20 3:11 PM, Eric W. Biederman wrote: >>>>> +static inline int __down_read_interruptible(struct rw_semaphore *sem) >>>>> +{ >>>>> + if (!rwsem_read_trylock(sem)) { >>>>> + if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_INTERRUPTIBLE))) >>>>> + return -EINTR; >>>>> + DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem); >>>>> + } else { >>>>> + rwsem_set_reader_owned(sem); >>>>> + } >>>>> + return 0; >>>>> +} >>>>> + >>>>> static inline int __down_read_killable(struct rw_semaphore *sem) >>>>> { >>>>> if (!rwsem_read_trylock(sem)) { >>>>> @@ -1495,6 +1507,20 @@ void __sched down_read(struct rw_semaphore *sem) >>>>> } >>>>> EXPORT_SYMBOL(down_read); >>>>> +int __sched down_read_interruptible(struct rw_semaphore *sem) >>>>> +{ >>>>> + might_sleep(); >>>>> + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_); >>>>> + >>>>> + if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_interruptible)) { >>>>> + rwsem_release(&sem->dep_map, _RET_IP_); >>>>> + return -EINTR; >>>>> + } >>>>> + >>>>> + return 0; >>>>> +} >>>>> +EXPORT_SYMBOL(down_read_interruptible); >>>>> + >>>>> int __sched down_read_killable(struct rw_semaphore *sem) >>>>> { >>>>> might_sleep(); >>>> Acked-by: Waiman Long >>> Yeah, that seems correct.. There's an unfortunate amount of copy-paste >>> there though. >>> >>> Do we want to follow that up with something like this? >> I am actually thinking about similar streamlining once the patch lands. >> >> Your suggested changes look fine to me. > How much more difficult would it be to also add a timeout option? > I looked at adding one to the mutex code - and fell into a big pile > of replicated code. > > ISTM that one the initial locked exchange (and spin) fails a few > extra instructions when heading for the sleep don't really matter > Actually, I had tried that before. See https://lore.kernel.org/lkml/20190911150537.19527-1-longman@redhat.com/ That is for rwsem, but the same can be done for mutex. However, Peter didn't seem to like the idea of a timeout parameter. Anyway, it is certainly doable if there is a good use case for it. Cheers, Longman