From patchwork Thu Mar 29 20:08:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 10316115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 97D12602D6 for ; Thu, 29 Mar 2018 20:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 874032A16A for ; Thu, 29 Mar 2018 20:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AF622A4EA; Thu, 29 Mar 2018 20:09:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10CD42A16A for ; Thu, 29 Mar 2018 20:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751199AbeC2UJO convert rfc822-to-8bit (ORCPT ); Thu, 29 Mar 2018 16:09:14 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:52496 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbeC2UJM (ORCPT ); Thu, 29 Mar 2018 16:09:12 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1f1dr8-00007i-80; Thu, 29 Mar 2018 14:09:06 -0600 Received: from 67-3-145-25.omah.qwest.net ([67.3.145.25] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1f1dr6-0001mC-GI; Thu, 29 Mar 2018 14:09:06 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Manfred Spraul Cc: Davidlohr Bueso , Waiman Long , Michael Kerrisk , "Luis R. Rodriguez" , Kees Cook , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Al Viro , Matthew Wilcox , Stanislav Kinsbursky , Linux Containers , linux-api@vger.kernel.org References: <1520885744-1546-1-git-send-email-longman@redhat.com> <1520885744-1546-5-git-send-email-longman@redhat.com> <87woyfyh57.fsf@xmission.com> <5d4a858a-3136-5ef4-76fe-a61e7f2aed56@redhat.com> <87o9jru3bf.fsf@xmission.com> <935a7c50-50cc-2dc0-33bb-92c000d039bc@redhat.com> <87woyego2u.fsf_-_@xmission.com> <047c6ed6-6581-b543-ba3d-cadc543d3d25@redhat.com> <87h8ph6u67.fsf@xmission.com> <7d3a1f93-f8e5-5325-f9a7-0079f7777b6f@redhat.com> <20180329021409.gcjjrmviw2lckbfk@linux-n805> <3e201de2-bed2-6f7d-0783-700d095142e0@colorfullife.com> Date: Thu, 29 Mar 2018 15:08:01 -0500 In-Reply-To: <3e201de2-bed2-6f7d-0783-700d095142e0@colorfullife.com> (Manfred Spraul's message of "Thu, 29 Mar 2018 10:47:45 +0200") Message-ID: <87y3ia3ase.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1f1dr6-0001mC-GI; ; ; mid=<87y3ia3ase.fsf@xmission.com>; ; ; hst=in02.mta.xmission.com; ; ; ip=67.3.145.25; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX1+bzGMlP7Kq5tqGNqizT3u+KsbSXhZ2tZk= X-SA-Exim-Connect-IP: 67.3.145.25 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [RFC][PATCH] ipc: Remove IPCMNI X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Manfred Spraul writes: >>>>> On 03/14/2018 08:49 PM, Eric W. Biederman wrote: >>>>>> To make it possible to keep checkpoint/restore working I have renamed >>>>>> the sysctls from xxx_next_id to xxx_nextid.  That is enough change that >>>>>> a smart CRIU implementation can see that what is exported has changed, >>>>>> and act accordingly.  New kernels will be able to restore the old id's. >>>>>> >>>>>> This code still needs some real world testing to verify my assumptions. >>>>>> And some work with the CRIU implementations to actually add the code >>>>>> that deals with the new for of id assignment. >>>>>> > It means that all existing checkpoint/restore application will not work with a > new kernel. > Everyone must first update the checkpoint/restore application, then update the > kernel. > > Is this acceptable? There is no nead. I just reread through how next_id is implementated in ipc/util.c and I had been reading it wrong. There is no need to change the sysctl. What criu needs is an interface that specifies the next_id to allocate both the high and the low bits and that is what this the sysctl provides. The implemenation could use a little cleanup so it is easier to understand something like this perhaps: Eric diff --git a/ipc/util.c b/ipc/util.c index 3783b7991cc7..2d4ec6e5b70b 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -192,46 +192,32 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key) return NULL; } -#ifdef CONFIG_CHECKPOINT_RESTORE -/* - * Specify desired id for next allocated IPC object. - */ -#define ipc_idr_alloc(ids, new) \ - idr_alloc(&(ids)->ipcs_idr, (new), \ - (ids)->next_id < 0 ? 0 : ipcid_to_idx((ids)->next_id),\ - 0, GFP_NOWAIT) - -static inline int ipc_buildid(int id, struct ipc_ids *ids, - struct kern_ipc_perm *new) -{ - if (ids->next_id < 0) { /* default, behave as !CHECKPOINT_RESTORE */ - new->seq = ids->seq++; - if (ids->seq > IPCID_SEQ_MAX) - ids->seq = 0; - } else { - new->seq = ipcid_to_seqx(ids->next_id); - ids->next_id = -1; - } - return SEQ_MULTIPLIER * new->seq + id; -} - -#else -#define ipc_idr_alloc(ids, new) \ - idr_alloc(&(ids)->ipcs_idr, (new), 0, 0, GFP_NOWAIT) - -static inline int ipc_buildid(int id, struct ipc_ids *ids, - struct kern_ipc_perm *new) +static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new) { + int id; +#ifdef CONFIG_CHECKPOINT_RESTORE + if (unlikely(new->id >= 0)) { + int idx = ipcid_to_idx(new->id); + id = idr_alloc(&ids->ipcs_idr, new, idx, 0, GFP_NOWAIT); + if (id < 0) + return id; + if (id != idx) { + idr_remove(&ids->ipcs_idr, id); + return -EBUSY; + } + new->seq = ipcid_to_seqx(new->id); + return id; + } +#endif + id = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); new->seq = ids->seq++; if (ids->seq > IPCID_SEQ_MAX) ids->seq = 0; - - return SEQ_MULTIPLIER * new->seq + id; + new->id = SEQ_MULTIPLIER * new->seq + id; + return id; } -#endif /* CONFIG_CHECKPOINT_RESTORE */ - /** * ipc_addid - add an ipc identifier * @ids: ipc identifier set @@ -269,6 +255,10 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit) new->cuid = new->uid = euid; new->gid = new->cgid = egid; + new->id = ids->next_id; + if (new->id >= 0) + ids->next_id = -1; + id = ipc_idr_alloc(ids, new); idr_preload_end(); @@ -290,8 +280,6 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit) if (id > ids->max_id) ids->max_id = id; - new->id = ipc_buildid(id, ids, new); - return id; }